Skip to content

Commit dc09a0c

Browse files
authored
Merge pull request #3080 from stof/return_types
Add native return types
2 parents 49f2c44 + fd22eae commit dc09a0c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+82
-260
lines changed

src/Controller/SecurityController.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,12 @@ public function loginAction(): Response
4949
]);
5050
}
5151

52-
/**
53-
* @return never
54-
*/
55-
public function checkAction()
52+
public function checkAction(): never
5653
{
5754
throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.');
5855
}
5956

60-
/**
61-
* @return never
62-
*/
63-
public function logoutAction()
57+
public function logoutAction(): never
6458
{
6559
throw new \RuntimeException('You must activate the logout in your security firewall configuration.');
6660
}

src/Doctrine/UserManager.php

+7-21
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,16 @@ public function __construct(PasswordUpdaterInterface $passwordUpdater, Canonical
4343
$this->class = $class;
4444
}
4545

46-
/**
47-
* @return void
48-
*/
49-
public function deleteUser(UserInterface $user)
46+
public function deleteUser(UserInterface $user): void
5047
{
5148
$this->objectManager->remove($user);
5249
$this->objectManager->flush();
5350
}
5451

5552
/**
56-
* @return string
57-
*
5853
* @phpstan-return class-string<UserInterface>
5954
*/
60-
public function getClass()
55+
public function getClass(): string
6156
{
6257
if (false !== strpos($this->class, ':')) {
6358
$metadata = $this->objectManager->getClassMetadata($this->class);
@@ -67,34 +62,25 @@ public function getClass()
6762
return $this->class;
6863
}
6964

70-
/**
71-
* @return UserInterface|null
72-
*/
73-
public function findUserBy(array $criteria)
65+
public function findUserBy(array $criteria): ?UserInterface
7466
{
7567
return $this->getRepository()->findOneBy($criteria);
7668
}
7769

7870
/**
7971
* @return iterable<UserInterface>
8072
*/
81-
public function findUsers()
73+
public function findUsers(): iterable
8274
{
8375
return $this->getRepository()->findAll();
8476
}
8577

86-
/**
87-
* @return void
88-
*/
89-
public function reloadUser(UserInterface $user)
78+
public function reloadUser(UserInterface $user): void
9079
{
9180
$this->objectManager->refresh($user);
9281
}
9382

94-
/**
95-
* @return void
96-
*/
97-
public function updateUser(UserInterface $user, $andFlush = true)
83+
public function updateUser(UserInterface $user, $andFlush = true): void
9884
{
9985
$this->updateCanonicalFields($user);
10086
$this->updatePassword($user);
@@ -108,7 +94,7 @@ public function updateUser(UserInterface $user, $andFlush = true)
10894
/**
10995
* @return ObjectRepository<UserInterface>
11096
*/
111-
protected function getRepository()
97+
protected function getRepository(): ObjectRepository
11298
{
11399
return $this->objectManager->getRepository($this->getClass());
114100
}

src/Event/FilterUserResponseEvent.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ public function getResponse(): Response
3535

3636
/**
3737
* Sets a new response object.
38-
*
39-
* @return void
4038
*/
41-
public function setResponse(Response $response)
39+
public function setResponse(Response $response): void
4240
{
4341
$this->response = $response;
4442
}

src/Event/FormEvent.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ public function getRequest(): Request
5252
return $this->request;
5353
}
5454

55-
/**
56-
* @return void
57-
*/
58-
public function setResponse(Response $response)
55+
public function setResponse(Response $response): void
5956
{
6057
$this->response = $response;
6158
}

src/Event/GetResponseNullableUserEvent.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ public function getRequest(): Request
5454
return $this->request;
5555
}
5656

57-
/**
58-
* @return void
59-
*/
60-
public function setResponse(Response $response)
57+
public function setResponse(Response $response): void
6158
{
6259
$this->response = $response;
6360
}

src/Event/GetResponseUserEvent.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ final class GetResponseUserEvent extends UserEvent
2020
*/
2121
private $response;
2222

23-
/**
24-
* @return void
25-
*/
26-
public function setResponse(Response $response)
23+
public function setResponse(Response $response): void
2724
{
2825
$this->response = $response;
2926
}

src/EventListener/AuthenticationListener.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,8 @@ public static function getSubscribedEvents(): array
5656

5757
/**
5858
* @param string $eventName
59-
*
60-
* @return void
6159
*/
62-
public function authenticate(FilterUserResponseEvent $event, $eventName, EventDispatcherInterface $eventDispatcher)
60+
public function authenticate(FilterUserResponseEvent $event, $eventName, EventDispatcherInterface $eventDispatcher): void
6361
{
6462
try {
6563
$this->loginManager->logInUser($this->firewallName, $event->getUser(), $event->getResponse());

src/EventListener/EmailConfirmationListener.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ public static function getSubscribedEvents(): array
4545
];
4646
}
4747

48-
/**
49-
* @return void
50-
*/
51-
public function onRegistrationSuccess(FormEvent $event)
48+
public function onRegistrationSuccess(FormEvent $event): void
5249
{
5350
/** @var \FOS\UserBundle\Model\UserInterface $user */
5451
$user = $event->getForm()->getData();

src/EventListener/FlashListener.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,8 @@ public static function getSubscribedEvents(): array
6464

6565
/**
6666
* @param string $eventName
67-
*
68-
* @return void
6967
*/
70-
public function addSuccessFlash(Event $event, $eventName)
68+
public function addSuccessFlash(Event $event, $eventName): void
7169
{
7270
if (!isset(self::$successMessages[$eventName])) {
7371
throw new \InvalidArgumentException('This event does not correspond to a known flash message');

src/EventListener/LastLoginListener.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,15 @@ public static function getSubscribedEvents(): array
4545
];
4646
}
4747

48-
/**
49-
* @return void
50-
*/
51-
public function onImplicitLogin(UserEvent $event)
48+
public function onImplicitLogin(UserEvent $event): void
5249
{
5350
$user = $event->getUser();
5451

5552
$user->setLastLogin(new \DateTime());
5653
$this->userManager->updateUser($user);
5754
}
5855

59-
/**
60-
* @return void
61-
*/
62-
public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
56+
public function onSecurityInteractiveLogin(InteractiveLoginEvent $event): void
6357
{
6458
$user = $event->getAuthenticationToken()->getUser();
6559

src/EventListener/ResettingListener.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,14 @@ public static function getSubscribedEvents(): array
5252
];
5353
}
5454

55-
/**
56-
* @return void
57-
*/
58-
public function onResettingResetInitialize(GetResponseUserEvent $event)
55+
public function onResettingResetInitialize(GetResponseUserEvent $event): void
5956
{
6057
if (!$event->getUser()->isPasswordRequestNonExpired($this->tokenTtl)) {
6158
$event->setResponse(new RedirectResponse($this->router->generate('fos_user_resetting_request')));
6259
}
6360
}
6461

65-
/**
66-
* @return void
67-
*/
68-
public function onResettingResetSuccess(FormEvent $event)
62+
public function onResettingResetSuccess(FormEvent $event): void
6963
{
7064
/** @var \FOS\UserBundle\Model\UserInterface $user */
7165
$user = $event->getForm()->getData();

src/Form/Factory/FactoryInterface.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,5 @@
1515

1616
interface FactoryInterface
1717
{
18-
/**
19-
* @return FormInterface
20-
*/
21-
public function createForm();
18+
public function createForm(): FormInterface;
2219
}

src/Form/Factory/FormFactory.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@ public function __construct(FormFactoryInterface $formFactory, $name, $type, ?ar
5353

5454
/**
5555
* @param array<string, mixed> $options
56-
*
57-
* @return FormInterface
5856
*/
59-
public function createForm(array $options = [])
57+
public function createForm(array $options = []): FormInterface
6058
{
6159
$options = array_merge(['validation_groups' => $this->validationGroups], $options);
6260

src/Mailer/MailerInterface.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,11 @@ interface MailerInterface
2020
{
2121
/**
2222
* Send an email to a user to confirm the account creation.
23-
*
24-
* @return void
2523
*/
26-
public function sendConfirmationEmailMessage(UserInterface $user);
24+
public function sendConfirmationEmailMessage(UserInterface $user): void;
2725

2826
/**
2927
* Send an email to a user to confirm the password reset.
30-
*
31-
* @return void
3228
*/
33-
public function sendResettingEmailMessage(UserInterface $user);
29+
public function sendResettingEmailMessage(UserInterface $user): void;
3430
}

src/Mailer/NoopMailer.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,12 @@
2222
*/
2323
final class NoopMailer implements MailerInterface
2424
{
25-
/**
26-
* @return void
27-
*/
28-
public function sendConfirmationEmailMessage(UserInterface $user)
25+
public function sendConfirmationEmailMessage(UserInterface $user): void
2926
{
3027
// nothing happens.
3128
}
3229

33-
/**
34-
* @return void
35-
*/
36-
public function sendResettingEmailMessage(UserInterface $user)
30+
public function sendResettingEmailMessage(UserInterface $user): void
3731
{
3832
// nothing happens.
3933
}

src/Model/UserManager.php

+9-36
Original file line numberDiff line numberDiff line change
@@ -31,37 +31,25 @@ public function __construct(PasswordUpdaterInterface $passwordUpdater, Canonical
3131
$this->canonicalFieldsUpdater = $canonicalFieldsUpdater;
3232
}
3333

34-
/**
35-
* @return UserInterface
36-
*/
37-
public function createUser()
34+
public function createUser(): UserInterface
3835
{
3936
$class = $this->getClass();
4037
$user = new $class();
4138

4239
return $user;
4340
}
4441

45-
/**
46-
* @return UserInterface|null
47-
*/
48-
public function findUserByEmail($email)
42+
public function findUserByEmail($email): ?UserInterface
4943
{
5044
return $this->findUserBy(['emailCanonical' => $this->canonicalFieldsUpdater->canonicalizeEmail($email)]);
5145
}
5246

53-
/**
54-
* @return UserInterface|null
55-
*/
56-
public function findUserByUsername($username)
47+
public function findUserByUsername($username): ?UserInterface
5748
{
5849
return $this->findUserBy(['usernameCanonical' => $this->canonicalFieldsUpdater->canonicalizeUsername($username)]);
5950
}
6051

61-
/**
62-
* @return UserInterface|null
63-
*/
64-
public function findUserByUsernameOrEmail($usernameOrEmail)
52+
public function findUserByUsernameOrEmail($usernameOrEmail): ?UserInterface
6553
{
6654
if (preg_match('/^.+\@\S+\.\S+$/', $usernameOrEmail)) {
6755
$user = $this->findUserByEmail($usernameOrEmail);
@@ -73,42 +61,27 @@ public function findUserByUsernameOrEmail($usernameOrEmail)
7361
return $this->findUserByUsername($usernameOrEmail);
7462
}
7563

76-
/**
77-
* @return UserInterface|null
78-
*/
79-
public function findUserByConfirmationToken($token)
64+
public function findUserByConfirmationToken($token): ?UserInterface
8065
{
8166
return $this->findUserBy(['confirmationToken' => $token]);
8267
}
8368

84-
/**
85-
* @return void
86-
*/
87-
public function updateCanonicalFields(UserInterface $user)
69+
public function updateCanonicalFields(UserInterface $user): void
8870
{
8971
$this->canonicalFieldsUpdater->updateCanonicalFields($user);
9072
}
9173

92-
/**
93-
* @return void
94-
*/
95-
public function updatePassword(UserInterface $user)
74+
public function updatePassword(UserInterface $user): void
9675
{
9776
$this->passwordUpdater->hashPassword($user);
9877
}
9978

100-
/**
101-
* @return PasswordUpdaterInterface
102-
*/
103-
protected function getPasswordUpdater()
79+
protected function getPasswordUpdater(): PasswordUpdaterInterface
10480
{
10581
return $this->passwordUpdater;
10682
}
10783

108-
/**
109-
* @return CanonicalFieldsUpdater
110-
*/
111-
protected function getCanonicalFieldsUpdater()
84+
protected function getCanonicalFieldsUpdater(): CanonicalFieldsUpdater
11285
{
11386
return $this->canonicalFieldsUpdater;
11487
}

0 commit comments

Comments
 (0)