From 865be1eacecd1e289ab3bc6c1b6b3a5a068d3168 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Tue, 25 Jun 2024 09:42:19 +0200 Subject: [PATCH] Add native return types --- src/Controller/SecurityController.php | 10 +--- src/Doctrine/UserManager.php | 28 +++-------- src/Event/FilterUserResponseEvent.php | 4 +- src/Event/FormEvent.php | 5 +- src/Event/GetResponseNullableUserEvent.php | 5 +- src/Event/GetResponseUserEvent.php | 5 +- src/EventListener/AuthenticationListener.php | 4 +- .../EmailConfirmationListener.php | 5 +- src/EventListener/FlashListener.php | 4 +- src/EventListener/LastLoginListener.php | 10 +--- src/EventListener/ResettingListener.php | 10 +--- src/Form/Factory/FactoryInterface.php | 5 +- src/Form/Factory/FormFactory.php | 4 +- src/Mailer/MailerInterface.php | 8 +-- src/Mailer/NoopMailer.php | 10 +--- src/Model/UserManager.php | 45 ++++------------- src/Model/UserManagerInterface.php | 50 +++++-------------- src/Security/LoginManager.php | 4 +- src/Security/LoginManagerInterface.php | 4 +- src/Util/CanonicalFieldsUpdater.php | 5 +- src/Util/Canonicalizer.php | 2 +- src/Util/CanonicalizerInterface.php | 4 +- src/Util/HashingPasswordUpdater.php | 5 +- src/Util/PasswordUpdaterInterface.php | 4 +- src/Util/TokenGenerator.php | 2 +- src/Util/TokenGeneratorInterface.php | 5 +- src/Util/UserManipulator.php | 20 ++------ tests/Command/ActivateUserCommandTest.php | 5 +- tests/Command/ChangePasswordCommandTest.php | 5 +- tests/Command/CreateUserCommandTest.php | 5 +- tests/Command/DeactivateUserCommandTest.php | 5 +- tests/Command/DemoteUserCommandTest.php | 5 +- tests/Command/PromoteUserCommandTest.php | 5 +- .../FOSUserExtensionTest.php | 8 +-- tests/Doctrine/UserManagerTest.php | 2 +- tests/Model/UserManagerTest.php | 10 ++-- tests/Model/UserTest.php | 5 +- tests/Routing/RoutingTest.php | 2 +- tests/Util/CanonicalFieldsUpdaterTest.php | 5 +- tests/Util/CanonicalizerTest.php | 2 +- tests/Util/UserManipulatorTest.php | 8 +-- 41 files changed, 82 insertions(+), 257 deletions(-) diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php index e0fda6a458..afb7d7d9b0 100644 --- a/src/Controller/SecurityController.php +++ b/src/Controller/SecurityController.php @@ -49,18 +49,12 @@ public function loginAction(): Response ]); } - /** - * @return never - */ - public function checkAction() + public function checkAction(): never { throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.'); } - /** - * @return never - */ - public function logoutAction() + public function logoutAction(): never { throw new \RuntimeException('You must activate the logout in your security firewall configuration.'); } diff --git a/src/Doctrine/UserManager.php b/src/Doctrine/UserManager.php index e74b5fa3cb..eda9cb9583 100644 --- a/src/Doctrine/UserManager.php +++ b/src/Doctrine/UserManager.php @@ -43,21 +43,16 @@ public function __construct(PasswordUpdaterInterface $passwordUpdater, Canonical $this->class = $class; } - /** - * @return void - */ - public function deleteUser(UserInterface $user) + public function deleteUser(UserInterface $user): void { $this->objectManager->remove($user); $this->objectManager->flush(); } /** - * @return string - * * @phpstan-return class-string */ - public function getClass() + public function getClass(): string { if (false !== strpos($this->class, ':')) { $metadata = $this->objectManager->getClassMetadata($this->class); @@ -67,10 +62,7 @@ public function getClass() return $this->class; } - /** - * @return UserInterface|null - */ - public function findUserBy(array $criteria) + public function findUserBy(array $criteria): ?UserInterface { return $this->getRepository()->findOneBy($criteria); } @@ -78,23 +70,17 @@ public function findUserBy(array $criteria) /** * @return iterable */ - public function findUsers() + public function findUsers(): iterable { return $this->getRepository()->findAll(); } - /** - * @return void - */ - public function reloadUser(UserInterface $user) + public function reloadUser(UserInterface $user): void { $this->objectManager->refresh($user); } - /** - * @return void - */ - public function updateUser(UserInterface $user, $andFlush = true) + public function updateUser(UserInterface $user, $andFlush = true): void { $this->updateCanonicalFields($user); $this->updatePassword($user); @@ -108,7 +94,7 @@ public function updateUser(UserInterface $user, $andFlush = true) /** * @return ObjectRepository */ - protected function getRepository() + protected function getRepository(): ObjectRepository { return $this->objectManager->getRepository($this->getClass()); } diff --git a/src/Event/FilterUserResponseEvent.php b/src/Event/FilterUserResponseEvent.php index 306c72190a..5cf7e0af68 100644 --- a/src/Event/FilterUserResponseEvent.php +++ b/src/Event/FilterUserResponseEvent.php @@ -35,10 +35,8 @@ public function getResponse(): Response /** * Sets a new response object. - * - * @return void */ - public function setResponse(Response $response) + public function setResponse(Response $response): void { $this->response = $response; } diff --git a/src/Event/FormEvent.php b/src/Event/FormEvent.php index c0dd0c858c..fd70535e1a 100644 --- a/src/Event/FormEvent.php +++ b/src/Event/FormEvent.php @@ -52,10 +52,7 @@ public function getRequest(): Request return $this->request; } - /** - * @return void - */ - public function setResponse(Response $response) + public function setResponse(Response $response): void { $this->response = $response; } diff --git a/src/Event/GetResponseNullableUserEvent.php b/src/Event/GetResponseNullableUserEvent.php index a359e18480..8308b97c7e 100644 --- a/src/Event/GetResponseNullableUserEvent.php +++ b/src/Event/GetResponseNullableUserEvent.php @@ -54,10 +54,7 @@ public function getRequest(): Request return $this->request; } - /** - * @return void - */ - public function setResponse(Response $response) + public function setResponse(Response $response): void { $this->response = $response; } diff --git a/src/Event/GetResponseUserEvent.php b/src/Event/GetResponseUserEvent.php index af965a777f..48bca6460e 100644 --- a/src/Event/GetResponseUserEvent.php +++ b/src/Event/GetResponseUserEvent.php @@ -20,10 +20,7 @@ final class GetResponseUserEvent extends UserEvent */ private $response; - /** - * @return void - */ - public function setResponse(Response $response) + public function setResponse(Response $response): void { $this->response = $response; } diff --git a/src/EventListener/AuthenticationListener.php b/src/EventListener/AuthenticationListener.php index 6494672cdf..b817942fd0 100644 --- a/src/EventListener/AuthenticationListener.php +++ b/src/EventListener/AuthenticationListener.php @@ -56,10 +56,8 @@ public static function getSubscribedEvents(): array /** * @param string $eventName - * - * @return void */ - public function authenticate(FilterUserResponseEvent $event, $eventName, EventDispatcherInterface $eventDispatcher) + public function authenticate(FilterUserResponseEvent $event, $eventName, EventDispatcherInterface $eventDispatcher): void { try { $this->loginManager->logInUser($this->firewallName, $event->getUser(), $event->getResponse()); diff --git a/src/EventListener/EmailConfirmationListener.php b/src/EventListener/EmailConfirmationListener.php index 9a3ed5e070..450c8207a4 100644 --- a/src/EventListener/EmailConfirmationListener.php +++ b/src/EventListener/EmailConfirmationListener.php @@ -45,10 +45,7 @@ public static function getSubscribedEvents(): array ]; } - /** - * @return void - */ - public function onRegistrationSuccess(FormEvent $event) + public function onRegistrationSuccess(FormEvent $event): void { /** @var \FOS\UserBundle\Model\UserInterface $user */ $user = $event->getForm()->getData(); diff --git a/src/EventListener/FlashListener.php b/src/EventListener/FlashListener.php index 09facc324e..ff8a5b5c65 100644 --- a/src/EventListener/FlashListener.php +++ b/src/EventListener/FlashListener.php @@ -64,10 +64,8 @@ public static function getSubscribedEvents(): array /** * @param string $eventName - * - * @return void */ - public function addSuccessFlash(Event $event, $eventName) + public function addSuccessFlash(Event $event, $eventName): void { if (!isset(self::$successMessages[$eventName])) { throw new \InvalidArgumentException('This event does not correspond to a known flash message'); diff --git a/src/EventListener/LastLoginListener.php b/src/EventListener/LastLoginListener.php index 556de6d0e3..e1c8d3cbf3 100644 --- a/src/EventListener/LastLoginListener.php +++ b/src/EventListener/LastLoginListener.php @@ -45,10 +45,7 @@ public static function getSubscribedEvents(): array ]; } - /** - * @return void - */ - public function onImplicitLogin(UserEvent $event) + public function onImplicitLogin(UserEvent $event): void { $user = $event->getUser(); @@ -56,10 +53,7 @@ public function onImplicitLogin(UserEvent $event) $this->userManager->updateUser($user); } - /** - * @return void - */ - public function onSecurityInteractiveLogin(InteractiveLoginEvent $event) + public function onSecurityInteractiveLogin(InteractiveLoginEvent $event): void { $user = $event->getAuthenticationToken()->getUser(); diff --git a/src/EventListener/ResettingListener.php b/src/EventListener/ResettingListener.php index 47960b0757..758553eeb5 100644 --- a/src/EventListener/ResettingListener.php +++ b/src/EventListener/ResettingListener.php @@ -52,20 +52,14 @@ public static function getSubscribedEvents(): array ]; } - /** - * @return void - */ - public function onResettingResetInitialize(GetResponseUserEvent $event) + public function onResettingResetInitialize(GetResponseUserEvent $event): void { if (!$event->getUser()->isPasswordRequestNonExpired($this->tokenTtl)) { $event->setResponse(new RedirectResponse($this->router->generate('fos_user_resetting_request'))); } } - /** - * @return void - */ - public function onResettingResetSuccess(FormEvent $event) + public function onResettingResetSuccess(FormEvent $event): void { /** @var \FOS\UserBundle\Model\UserInterface $user */ $user = $event->getForm()->getData(); diff --git a/src/Form/Factory/FactoryInterface.php b/src/Form/Factory/FactoryInterface.php index ee211743af..20df60508b 100644 --- a/src/Form/Factory/FactoryInterface.php +++ b/src/Form/Factory/FactoryInterface.php @@ -15,8 +15,5 @@ interface FactoryInterface { - /** - * @return FormInterface - */ - public function createForm(); + public function createForm(): FormInterface; } diff --git a/src/Form/Factory/FormFactory.php b/src/Form/Factory/FormFactory.php index 115a32e418..38a0be62c5 100644 --- a/src/Form/Factory/FormFactory.php +++ b/src/Form/Factory/FormFactory.php @@ -53,10 +53,8 @@ public function __construct(FormFactoryInterface $formFactory, $name, $type, ?ar /** * @param array $options - * - * @return FormInterface */ - public function createForm(array $options = []) + public function createForm(array $options = []): FormInterface { $options = array_merge(['validation_groups' => $this->validationGroups], $options); diff --git a/src/Mailer/MailerInterface.php b/src/Mailer/MailerInterface.php index eafa6d63fa..399edaf269 100644 --- a/src/Mailer/MailerInterface.php +++ b/src/Mailer/MailerInterface.php @@ -20,15 +20,11 @@ interface MailerInterface { /** * Send an email to a user to confirm the account creation. - * - * @return void */ - public function sendConfirmationEmailMessage(UserInterface $user); + public function sendConfirmationEmailMessage(UserInterface $user): void; /** * Send an email to a user to confirm the password reset. - * - * @return void */ - public function sendResettingEmailMessage(UserInterface $user); + public function sendResettingEmailMessage(UserInterface $user): void; } diff --git a/src/Mailer/NoopMailer.php b/src/Mailer/NoopMailer.php index 8380348a02..290687ddf4 100644 --- a/src/Mailer/NoopMailer.php +++ b/src/Mailer/NoopMailer.php @@ -22,18 +22,12 @@ */ final class NoopMailer implements MailerInterface { - /** - * @return void - */ - public function sendConfirmationEmailMessage(UserInterface $user) + public function sendConfirmationEmailMessage(UserInterface $user): void { // nothing happens. } - /** - * @return void - */ - public function sendResettingEmailMessage(UserInterface $user) + public function sendResettingEmailMessage(UserInterface $user): void { // nothing happens. } diff --git a/src/Model/UserManager.php b/src/Model/UserManager.php index 60fd356cd9..3a14cdcd43 100644 --- a/src/Model/UserManager.php +++ b/src/Model/UserManager.php @@ -31,10 +31,7 @@ public function __construct(PasswordUpdaterInterface $passwordUpdater, Canonical $this->canonicalFieldsUpdater = $canonicalFieldsUpdater; } - /** - * @return UserInterface - */ - public function createUser() + public function createUser(): UserInterface { $class = $this->getClass(); $user = new $class(); @@ -42,26 +39,17 @@ public function createUser() return $user; } - /** - * @return UserInterface|null - */ - public function findUserByEmail($email) + public function findUserByEmail($email): ?UserInterface { return $this->findUserBy(['emailCanonical' => $this->canonicalFieldsUpdater->canonicalizeEmail($email)]); } - /** - * @return UserInterface|null - */ - public function findUserByUsername($username) + public function findUserByUsername($username): ?UserInterface { return $this->findUserBy(['usernameCanonical' => $this->canonicalFieldsUpdater->canonicalizeUsername($username)]); } - /** - * @return UserInterface|null - */ - public function findUserByUsernameOrEmail($usernameOrEmail) + public function findUserByUsernameOrEmail($usernameOrEmail): ?UserInterface { if (preg_match('/^.+\@\S+\.\S+$/', $usernameOrEmail)) { $user = $this->findUserByEmail($usernameOrEmail); @@ -73,42 +61,27 @@ public function findUserByUsernameOrEmail($usernameOrEmail) return $this->findUserByUsername($usernameOrEmail); } - /** - * @return UserInterface|null - */ - public function findUserByConfirmationToken($token) + public function findUserByConfirmationToken($token): ?UserInterface { return $this->findUserBy(['confirmationToken' => $token]); } - /** - * @return void - */ - public function updateCanonicalFields(UserInterface $user) + public function updateCanonicalFields(UserInterface $user): void { $this->canonicalFieldsUpdater->updateCanonicalFields($user); } - /** - * @return void - */ - public function updatePassword(UserInterface $user) + public function updatePassword(UserInterface $user): void { $this->passwordUpdater->hashPassword($user); } - /** - * @return PasswordUpdaterInterface - */ - protected function getPasswordUpdater() + protected function getPasswordUpdater(): PasswordUpdaterInterface { return $this->passwordUpdater; } - /** - * @return CanonicalFieldsUpdater - */ - protected function getCanonicalFieldsUpdater() + protected function getCanonicalFieldsUpdater(): CanonicalFieldsUpdater { return $this->canonicalFieldsUpdater; } diff --git a/src/Model/UserManagerInterface.php b/src/Model/UserManagerInterface.php index f85a4016fd..6c2d1cc501 100644 --- a/src/Model/UserManagerInterface.php +++ b/src/Model/UserManagerInterface.php @@ -28,104 +28,80 @@ interface UserManagerInterface { /** * Creates an empty user instance. - * - * @return UserInterface */ - public function createUser(); + public function createUser(): UserInterface; /** * Deletes a user. - * - * @return void */ - public function deleteUser(UserInterface $user); + public function deleteUser(UserInterface $user): void; /** * Finds one user by the given criteria. * * @param array $criteria - * - * @return UserInterface|null */ - public function findUserBy(array $criteria); + public function findUserBy(array $criteria): ?UserInterface; /** * Find a user by its username. * * @param string $username - * - * @return UserInterface|null */ - public function findUserByUsername($username); + public function findUserByUsername($username): ?UserInterface; /** * Finds a user by its email. * * @param string $email - * - * @return UserInterface|null */ - public function findUserByEmail($email); + public function findUserByEmail($email): ?UserInterface; /** * Finds a user by its username or email. * * @param string $usernameOrEmail - * - * @return UserInterface|null */ - public function findUserByUsernameOrEmail($usernameOrEmail); + public function findUserByUsernameOrEmail($usernameOrEmail): ?UserInterface; /** * Finds a user by its confirmationToken. * * @param string $token - * - * @return UserInterface|null */ - public function findUserByConfirmationToken($token); + public function findUserByConfirmationToken($token): ?UserInterface; /** * Returns a collection with all user instances. * * @return iterable */ - public function findUsers(); + public function findUsers(): iterable; /** * Returns the user's fully qualified class name. * - * @return string - * * @phpstan-return class-string */ - public function getClass(); + public function getClass(): string; /** * Reloads a user. - * - * @return void */ - public function reloadUser(UserInterface $user); + public function reloadUser(UserInterface $user): void; /** * Updates a user. - * - * @return void */ - public function updateUser(UserInterface $user); + public function updateUser(UserInterface $user): void; /** * Updates the canonical username and email fields for a user. - * - * @return void */ - public function updateCanonicalFields(UserInterface $user); + public function updateCanonicalFields(UserInterface $user): void; /** * Updates a user password if a plain password is set. - * - * @return void */ - public function updatePassword(UserInterface $user); + public function updatePassword(UserInterface $user): void; } diff --git a/src/Security/LoginManager.php b/src/Security/LoginManager.php index 7f606de236..3bc90f605c 100644 --- a/src/Security/LoginManager.php +++ b/src/Security/LoginManager.php @@ -84,10 +84,8 @@ final public function logInUser($firewallName, UserInterface $user, ?Response $r /** * @param string $firewall - * - * @return UsernamePasswordToken */ - protected function createToken($firewall, UserInterface $user) + protected function createToken($firewall, UserInterface $user): UsernamePasswordToken { return new UsernamePasswordToken($user, $firewall, $user->getRoles()); } diff --git a/src/Security/LoginManagerInterface.php b/src/Security/LoginManagerInterface.php index 84c0214541..5aa9a3f753 100644 --- a/src/Security/LoginManagerInterface.php +++ b/src/Security/LoginManagerInterface.php @@ -18,8 +18,6 @@ interface LoginManagerInterface { /** * @param string $firewallName - * - * @return void */ - public function logInUser($firewallName, UserInterface $user, ?Response $response = null); + public function logInUser($firewallName, UserInterface $user, ?Response $response = null): void; } diff --git a/src/Util/CanonicalFieldsUpdater.php b/src/Util/CanonicalFieldsUpdater.php index 1be388f647..923f3c7b79 100644 --- a/src/Util/CanonicalFieldsUpdater.php +++ b/src/Util/CanonicalFieldsUpdater.php @@ -31,10 +31,7 @@ public function __construct(CanonicalizerInterface $usernameCanonicalizer, Canon $this->emailCanonicalizer = $emailCanonicalizer; } - /** - * @return void - */ - public function updateCanonicalFields(UserInterface $user) + public function updateCanonicalFields(UserInterface $user): void { $user->setUsernameCanonical($this->canonicalizeUsername($user->getUsername())); $user->setEmailCanonical($this->canonicalizeEmail($user->getEmail())); diff --git a/src/Util/Canonicalizer.php b/src/Util/Canonicalizer.php index dab6c492f2..53f58ea1ba 100644 --- a/src/Util/Canonicalizer.php +++ b/src/Util/Canonicalizer.php @@ -13,7 +13,7 @@ class Canonicalizer implements CanonicalizerInterface { - public function canonicalize($string) + public function canonicalize($string): ?string { if (null === $string) { return null; diff --git a/src/Util/CanonicalizerInterface.php b/src/Util/CanonicalizerInterface.php index d1eb64ada1..ad893840b0 100644 --- a/src/Util/CanonicalizerInterface.php +++ b/src/Util/CanonicalizerInterface.php @@ -16,9 +16,7 @@ interface CanonicalizerInterface /** * @param string|null $string * - * @return string|null - * * @phpstan-return ($string is null ? null : string) */ - public function canonicalize($string); + public function canonicalize($string): ?string; } diff --git a/src/Util/HashingPasswordUpdater.php b/src/Util/HashingPasswordUpdater.php index f0619e5825..2d0e71f832 100644 --- a/src/Util/HashingPasswordUpdater.php +++ b/src/Util/HashingPasswordUpdater.php @@ -29,10 +29,7 @@ public function __construct(PasswordHasherFactoryInterface $passwordHasherFactor $this->passwordHasherFactory = $passwordHasherFactory; } - /** - * @return void - */ - public function hashPassword(UserInterface $user) + public function hashPassword(UserInterface $user): void { $plainPassword = $user->getPlainPassword(); diff --git a/src/Util/PasswordUpdaterInterface.php b/src/Util/PasswordUpdaterInterface.php index be689eea81..d628f17c64 100644 --- a/src/Util/PasswordUpdaterInterface.php +++ b/src/Util/PasswordUpdaterInterface.php @@ -23,8 +23,6 @@ interface PasswordUpdaterInterface * * The implement should be a no-op in case there is no new password (it should not erase the * existing hash with a wrong one). - * - * @return void */ - public function hashPassword(UserInterface $user); + public function hashPassword(UserInterface $user): void; } diff --git a/src/Util/TokenGenerator.php b/src/Util/TokenGenerator.php index b70654d6c2..0f303cd7c0 100644 --- a/src/Util/TokenGenerator.php +++ b/src/Util/TokenGenerator.php @@ -13,7 +13,7 @@ class TokenGenerator implements TokenGeneratorInterface { - public function generateToken() + public function generateToken(): string { return rtrim(strtr(base64_encode(random_bytes(32)), '+/', '-_'), '='); } diff --git a/src/Util/TokenGeneratorInterface.php b/src/Util/TokenGeneratorInterface.php index 17493d0246..cd5e573b39 100644 --- a/src/Util/TokenGeneratorInterface.php +++ b/src/Util/TokenGeneratorInterface.php @@ -13,8 +13,5 @@ interface TokenGeneratorInterface { - /** - * @return string - */ - public function generateToken(); + public function generateToken(): string; } diff --git a/src/Util/UserManipulator.php b/src/Util/UserManipulator.php index 9554ec9a76..31a8c91532 100644 --- a/src/Util/UserManipulator.php +++ b/src/Util/UserManipulator.php @@ -87,10 +87,8 @@ public function create($username, $password, $email, $active, $superadmin): User * Activates the given user. * * @param string $username - * - * @return void */ - public function activate($username) + public function activate($username): void { $user = $this->findUserByUsernameOrThrowException($username); $user->setEnabled(true); @@ -104,10 +102,8 @@ public function activate($username) * Deactivates the given user. * * @param string $username - * - * @return void */ - public function deactivate($username) + public function deactivate($username): void { $user = $this->findUserByUsernameOrThrowException($username); $user->setEnabled(false); @@ -122,10 +118,8 @@ public function deactivate($username) * * @param string $username * @param string $password - * - * @return void */ - public function changePassword($username, $password) + public function changePassword($username, $password): void { $user = $this->findUserByUsernameOrThrowException($username); $user->setPlainPassword($password); @@ -139,10 +133,8 @@ public function changePassword($username, $password) * Promotes the given user. * * @param string $username - * - * @return void */ - public function promote($username) + public function promote($username): void { $user = $this->findUserByUsernameOrThrowException($username); $user->setSuperAdmin(true); @@ -156,10 +148,8 @@ public function promote($username) * Demotes the given user. * * @param string $username - * - * @return void */ - public function demote($username) + public function demote($username): void { $user = $this->findUserByUsernameOrThrowException($username); $user->setSuperAdmin(false); diff --git a/tests/Command/ActivateUserCommandTest.php b/tests/Command/ActivateUserCommandTest.php index 31949e5a31..379855edef 100644 --- a/tests/Command/ActivateUserCommandTest.php +++ b/tests/Command/ActivateUserCommandTest.php @@ -57,10 +57,7 @@ public function testExecuteInteractiveWithQuestionHelper() $this->assertMatchesRegularExpression('/User "user" has been activated/', $commandTester->getDisplay()); } - /** - * @return CommandTester - */ - private function createCommandTester(UserManipulator $manipulator, ?Application $application = null) + private function createCommandTester(UserManipulator $manipulator, ?Application $application = null): CommandTester { if (null === $application) { $application = new Application(); diff --git a/tests/Command/ChangePasswordCommandTest.php b/tests/Command/ChangePasswordCommandTest.php index 07803b5fdc..397baa9e42 100644 --- a/tests/Command/ChangePasswordCommandTest.php +++ b/tests/Command/ChangePasswordCommandTest.php @@ -58,10 +58,7 @@ public function testExecuteInteractiveWithQuestionHelper() $this->assertMatchesRegularExpression('/Changed password for user user/', $commandTester->getDisplay()); } - /** - * @return CommandTester - */ - private function createCommandTester(UserManipulator $userManipulator, ?Application $application = null) + private function createCommandTester(UserManipulator $userManipulator, ?Application $application = null): CommandTester { if (null === $application) { $application = new Application(); diff --git a/tests/Command/CreateUserCommandTest.php b/tests/Command/CreateUserCommandTest.php index 938e531cf0..3789bffd58 100644 --- a/tests/Command/CreateUserCommandTest.php +++ b/tests/Command/CreateUserCommandTest.php @@ -61,10 +61,7 @@ public function testExecuteInteractiveWithQuestionHelper() $this->assertMatchesRegularExpression('/Created user user/', $commandTester->getDisplay()); } - /** - * @return CommandTester - */ - private function createCommandTester(UserManipulator $manipulator, ?Application $application = null) + private function createCommandTester(UserManipulator $manipulator, ?Application $application = null): CommandTester { if (null === $application) { $application = new Application(); diff --git a/tests/Command/DeactivateUserCommandTest.php b/tests/Command/DeactivateUserCommandTest.php index a731d29345..4f20700e7e 100644 --- a/tests/Command/DeactivateUserCommandTest.php +++ b/tests/Command/DeactivateUserCommandTest.php @@ -57,10 +57,7 @@ public function testExecuteInteractiveWithQuestionHelper() $this->assertMatchesRegularExpression('/User "user" has been deactivated/', $commandTester->getDisplay()); } - /** - * @return CommandTester - */ - private function createCommandTester(UserManipulator $manipulator, ?Application $application = null) + private function createCommandTester(UserManipulator $manipulator, ?Application $application = null): CommandTester { if (null === $application) { $application = new Application(); diff --git a/tests/Command/DemoteUserCommandTest.php b/tests/Command/DemoteUserCommandTest.php index 6392609f67..b2db91bf0e 100644 --- a/tests/Command/DemoteUserCommandTest.php +++ b/tests/Command/DemoteUserCommandTest.php @@ -58,10 +58,7 @@ public function testExecuteInteractiveWithQuestionHelper() $this->assertMatchesRegularExpression('/Role "role" has been removed from user "user"/', $commandTester->getDisplay()); } - /** - * @return CommandTester - */ - private function createCommandTester(UserManipulator $manipulator, ?Application $application = null) + private function createCommandTester(UserManipulator $manipulator, ?Application $application = null): CommandTester { if (null === $application) { $application = new Application(); diff --git a/tests/Command/PromoteUserCommandTest.php b/tests/Command/PromoteUserCommandTest.php index 2a99aecb3c..25b5e38f5d 100644 --- a/tests/Command/PromoteUserCommandTest.php +++ b/tests/Command/PromoteUserCommandTest.php @@ -58,10 +58,7 @@ public function testExecuteInteractiveWithQuestionHelper() $this->assertMatchesRegularExpression('/Role "role" has been added to user "user"/', $commandTester->getDisplay()); } - /** - * @return CommandTester - */ - private function createCommandTester(UserManipulator $manipulator, ?Application $application = null) + private function createCommandTester(UserManipulator $manipulator, ?Application $application = null): CommandTester { if (null === $application) { $application = new Application(); diff --git a/tests/DependencyInjection/FOSUserExtensionTest.php b/tests/DependencyInjection/FOSUserExtensionTest.php index 2903942e3b..65cec37c6d 100644 --- a/tests/DependencyInjection/FOSUserExtensionTest.php +++ b/tests/DependencyInjection/FOSUserExtensionTest.php @@ -363,9 +363,9 @@ public function testUserManagerSetFactory($dbDriver, $doctrineService) } /** - * @return array + * @return iterable */ - public function userManagerSetFactoryProvider() + public function userManagerSetFactoryProvider(): iterable { return [ ['orm', 'doctrine'], @@ -396,7 +396,7 @@ protected function createFullConfiguration() * * @return array */ - protected function getEmptyConfig() + protected function getEmptyConfig(): array { $yaml = << */ - protected function getFullConfig() + protected function getFullConfig(): array { $yaml = <<assertSame($user, $actualUser); } - /** - * @return mixed - */ - private function getUser() + private function getUser(): User&MockObject { return $this->getMockBuilder('FOS\UserBundle\Model\User') ->getMockForAbstractClass(); @@ -185,10 +183,8 @@ private function getUser() /** * @param array{PasswordUpdaterInterface, CanonicalFieldsUpdater} $args - * - * @return UserManager&MockObject */ - private function getUserManager(array $args) + private function getUserManager(array $args): UserManager&MockObject { return $this->getMockBuilder('FOS\UserBundle\Model\UserManager') ->setConstructorArgs($args) diff --git a/tests/Model/UserTest.php b/tests/Model/UserTest.php index e3249303c0..e4d225878c 100644 --- a/tests/Model/UserTest.php +++ b/tests/Model/UserTest.php @@ -98,10 +98,7 @@ public function testIsEqualTo() $this->assertFalse($user->isEqualTo($user4)); } - /** - * @return User - */ - protected function getUser() + protected function getUser(): User { return $this->getMockForAbstractClass('FOS\UserBundle\Model\User'); } diff --git a/tests/Routing/RoutingTest.php b/tests/Routing/RoutingTest.php index 8bbe3eebf3..0427ce2aa7 100644 --- a/tests/Routing/RoutingTest.php +++ b/tests/Routing/RoutingTest.php @@ -52,7 +52,7 @@ public function testLoadRouting($routeName, $path, array $methods) /** * @return iterable */ - public function loadRoutingProvider() + public function loadRoutingProvider(): iterable { return [ ['fos_user_change_password', '/change-password', ['GET', 'POST']], diff --git a/tests/Util/CanonicalFieldsUpdaterTest.php b/tests/Util/CanonicalFieldsUpdaterTest.php index 7aa07c521f..ee45fcc118 100644 --- a/tests/Util/CanonicalFieldsUpdaterTest.php +++ b/tests/Util/CanonicalFieldsUpdaterTest.php @@ -61,10 +61,7 @@ public function testUpdateCanonicalFields() $this->assertSame('user@example.com', $user->getEmailCanonical()); } - /** - * @return CanonicalizerInterface&MockObject - */ - private function getMockCanonicalizer() + private function getMockCanonicalizer(): CanonicalizerInterface&MockObject { return $this->getMockBuilder('FOS\UserBundle\Util\CanonicalizerInterface')->getMock(); } diff --git a/tests/Util/CanonicalizerTest.php b/tests/Util/CanonicalizerTest.php index 2fff2aaf31..ff56aecd2b 100644 --- a/tests/Util/CanonicalizerTest.php +++ b/tests/Util/CanonicalizerTest.php @@ -28,7 +28,7 @@ public function testCanonicalize(?string $source, ?string $expectedResult) /** * @return iterable */ - public function canonicalizeProvider() + public function canonicalizeProvider(): iterable { return [ [null, null], diff --git a/tests/Util/UserManipulatorTest.php b/tests/Util/UserManipulatorTest.php index b355f226e9..411f9f2e69 100644 --- a/tests/Util/UserManipulatorTest.php +++ b/tests/Util/UserManipulatorTest.php @@ -373,10 +373,8 @@ public function testRemoveRole() /** * @param string $event * @param bool $once - * - * @return MockObject&EventDispatcherInterface */ - protected function getEventDispatcherMock($event, $once = true) + protected function getEventDispatcherMock($event, $once = true): MockObject&EventDispatcherInterface { $eventDispatcherMock = $this->getMockBuilder(EventDispatcherInterface::class)->getMock(); @@ -389,10 +387,8 @@ protected function getEventDispatcherMock($event, $once = true) /** * @param bool $once - * - * @return MockObject&RequestStack */ - protected function getRequestStackMock($once = true) + protected function getRequestStackMock($once = true): MockObject&RequestStack { $requestStackMock = $this->getMockBuilder(RequestStack::class)->getMock();