Skip to content

Commit b455593

Browse files
committed
Improve types for static analysis
1 parent be29986 commit b455593

7 files changed

Lines changed: 27 additions & 22 deletions

File tree

src/Controller/ResettingController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function requestAction(): Response
7171
*/
7272
public function sendEmailAction(Request $request): Response
7373
{
74-
$username = $request->request->get('username');
74+
$username = $request->request->getString('username');
7575

7676
$user = $this->userManager->findUserByUsernameOrEmail($username);
7777

src/Doctrine/UserManager.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ class UserManager extends BaseUserManager
2727

2828
/**
2929
* @var string
30+
*
31+
* @phpstan-var class-string<UserInterface>
3032
*/
3133
private $class;
3234

3335
/**
3436
* Constructor.
3537
*
36-
* @param string $class
38+
* @phpstan-param class-string<UserInterface> $class
3739
*/
38-
public function __construct(PasswordUpdaterInterface $passwordUpdater, CanonicalFieldsUpdater $canonicalFieldsUpdater, ObjectManager $om, $class)
40+
public function __construct(PasswordUpdaterInterface $passwordUpdater, CanonicalFieldsUpdater $canonicalFieldsUpdater, ObjectManager $om, string $class)
3941
{
4042
parent::__construct($passwordUpdater, $canonicalFieldsUpdater);
4143

@@ -80,7 +82,7 @@ public function reloadUser(UserInterface $user): void
8082
$this->objectManager->refresh($user);
8183
}
8284

83-
public function updateUser(UserInterface $user, $andFlush = true): void
85+
public function updateUser(UserInterface $user, bool $andFlush = true): void
8486
{
8587
$this->updateCanonicalFields($user);
8688
$this->updatePassword($user);

src/Event/FormEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class FormEvent extends Event
2929
private $request;
3030

3131
/**
32-
* @var Response
32+
* @var Response|null
3333
*/
3434
private $response;
3535

src/Form/Type/UsernameFormType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
4141
$builder->addModelTransformer($this->usernameTransformer);
4242
}
4343

44-
public function getParent(): ?string
44+
public function getParent(): string
4545
{
4646
return TextType::class;
4747
}

src/Util/CanonicalFieldsUpdater.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public function updateCanonicalFields(UserInterface $user): void
4141
* Canonicalizes an email.
4242
*
4343
* @param string|null $email
44+
*
45+
* @phpstan-return ($email is null ? null : string)
4446
*/
4547
public function canonicalizeEmail($email): ?string
4648
{
@@ -51,6 +53,8 @@ public function canonicalizeEmail($email): ?string
5153
* Canonicalizes a username.
5254
*
5355
* @param string|null $username
56+
*
57+
* @phpstan-return ($username is null ? null : string)
5458
*/
5559
public function canonicalizeUsername($username): ?string
5660
{

tests/DependencyInjection/FOSUserExtensionTest.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@
2020
class FOSUserExtensionTest extends TestCase
2121
{
2222
/** @var ContainerBuilder */
23-
protected $configuration;
24-
25-
protected function tearDown(): void
26-
{
27-
unset($this->configuration);
28-
}
23+
private $configuration;
2924

3025
public function testUserLoadThrowsExceptionUnlessDatabaseDriverSet()
3126
{
@@ -157,8 +152,12 @@ public function testDisableChangePassword()
157152

158153
/**
159154
* @dataProvider providerEmailsDisabledFeature
155+
*
156+
* @param array<string, mixed> $testConfig
157+
* @param array{address: string, sender_name: string} $registration
158+
* @param array{address: string, sender_name: string} $resetting
160159
*/
161-
public function testEmailsDisabledFeature($testConfig, $registration, $resetting)
160+
public function testEmailsDisabledFeature(array $testConfig, array $registration, array $resetting)
162161
{
163162
$this->configuration = new ContainerBuilder();
164163
$loader = new FOSUserExtension();
@@ -170,7 +169,10 @@ public function testEmailsDisabledFeature($testConfig, $registration, $resetting
170169
$this->assertParameter($resetting, 'fos_user.resetting.email.from_address');
171170
}
172171

173-
public function providerEmailsDisabledFeature()
172+
/**
173+
* @return iterable<array{array<string, mixed>, array{address: string, sender_name: string}, array{address: string, sender_name: string}}>
174+
*/
175+
public function providerEmailsDisabledFeature(): iterable
174176
{
175177
$configBothFeaturesDisabled = ['registration' => false, 'resetting' => false];
176178
$configResettingDisabled = ['resetting' => false];
@@ -343,7 +345,7 @@ public function testUserLoadFlashesCanBeDisabled()
343345
/**
344346
* @dataProvider userManagerSetFactoryProvider
345347
*/
346-
public function testUserManagerSetFactory($dbDriver, $doctrineService)
348+
public function testUserManagerSetFactory(string $dbDriver, string $doctrineService)
347349
{
348350
$this->configuration = new ContainerBuilder();
349351
$loader = new FOSUserExtension();
@@ -357,6 +359,7 @@ public function testUserManagerSetFactory($dbDriver, $doctrineService)
357359

358360
$factory = $definition->getFactory();
359361

362+
$this->assertIsArray($factory);
360363
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $factory[0]);
361364
$this->assertSame('fos_user.doctrine_registry', (string) $factory[0]);
362365
$this->assertSame('getManager', $factory[1]);
@@ -373,27 +376,23 @@ public function userManagerSetFactoryProvider(): iterable
373376
];
374377
}
375378

376-
protected function createEmptyConfiguration()
379+
protected function createEmptyConfiguration(): void
377380
{
378381
$this->configuration = new ContainerBuilder();
379382
$loader = new FOSUserExtension();
380383
$config = $this->getEmptyConfig();
381384
$loader->load([$config], $this->configuration);
382-
$this->assertTrue($this->configuration instanceof ContainerBuilder);
383385
}
384386

385-
protected function createFullConfiguration()
387+
protected function createFullConfiguration(): void
386388
{
387389
$this->configuration = new ContainerBuilder();
388390
$loader = new FOSUserExtension();
389391
$config = $this->getFullConfig();
390392
$loader->load([$config], $this->configuration);
391-
$this->assertTrue($this->configuration instanceof ContainerBuilder);
392393
}
393394

394395
/**
395-
* getEmptyConfig.
396-
*
397396
* @return array<string, mixed>
398397
*/
399398
protected function getEmptyConfig(): array

tests/Security/UserCheckerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function testCheckPostAuthSuccess()
4646
$this->expectNotToPerformAssertions();
4747
}
4848

49-
private function getUser($isEnabled): User
49+
private function getUser(bool $isEnabled): User
5050
{
5151
$userMock = $this->getMockBuilder('FOS\UserBundle\Model\User')->getMock();
5252
$userMock

0 commit comments

Comments
 (0)