From 0bfa69a2ca28d12d85042050e17dc085bf920745 Mon Sep 17 00:00:00 2001 From: core23 Date: Fri, 1 Oct 2021 12:24:00 +0200 Subject: [PATCH] Add type hints --- src/Action/CheckRegistrationMailAction.php | 18 ++-------- src/Action/ConfirmRegistrationAction.php | 15 ++------ src/Action/EditProfileAction.php | 35 ++++++------------- src/Action/RegistrationAction.php | 30 +++++----------- src/Action/RegistrationConfirmedAction.php | 15 ++------ src/Action/ShowProfileAction.php | 12 ++----- src/Event/GetResponseRegistrationEvent.php | 17 +++------ src/Event/UserFormEvent.php | 6 ++-- src/EventListener/AlreadyLoggedinListener.php | 17 +++------ src/EventListener/AuthenticationListener.php | 10 ++---- .../EmailConfirmationListener.php | 20 +++-------- src/EventListener/FlashListener.php | 12 ++----- src/Form/Model/Profile.php | 10 ++---- src/Form/Model/Registration.php | 15 ++------ src/Form/Type/ProfileFormType.php | 7 ++-- src/Form/Type/RegistrationFormType.php | 21 ++++------- src/Mailer/Mail/RegistrationMail.php | 10 ++---- src/Mailer/Mailer.php | 20 +++-------- .../Action/RegisterActionIntegrationTest.php | 5 +-- .../NucleosProfileExtensionTest.php | 5 +-- .../AuthenticationListenerTest.php | 10 ++---- tests/EventListener/FlashListenerTest.php | 12 ++----- 22 files changed, 78 insertions(+), 244 deletions(-) diff --git a/src/Action/CheckRegistrationMailAction.php b/src/Action/CheckRegistrationMailAction.php index b60ca4bc..7de5a72a 100644 --- a/src/Action/CheckRegistrationMailAction.php +++ b/src/Action/CheckRegistrationMailAction.php @@ -20,24 +20,12 @@ final class CheckRegistrationMailAction { - /** - * @var UserManagerInterface - */ - private $userManager; + private UserManagerInterface $userManager; - /** - * @var Environment - */ - private $twig; + private Environment $twig; - /** - * @var RouterInterface - */ - private $router; + private RouterInterface $router; - /** - * CheckRegistrationMailAction constructor. - */ public function __construct(UserManagerInterface $userManager, Environment $twig, RouterInterface $router) { $this->userManager = $userManager; diff --git a/src/Action/ConfirmRegistrationAction.php b/src/Action/ConfirmRegistrationAction.php index b27606d7..0001fb68 100644 --- a/src/Action/ConfirmRegistrationAction.php +++ b/src/Action/ConfirmRegistrationAction.php @@ -23,20 +23,11 @@ final class ConfirmRegistrationAction { - /** - * @var EventDispatcherInterface - */ - private $eventDispatcher; + private EventDispatcherInterface $eventDispatcher; - /** - * @var UserManagerInterface - */ - private $userManager; + private UserManagerInterface $userManager; - /** - * @var RouterInterface - */ - private $router; + private RouterInterface $router; public function __construct( EventDispatcherInterface $eventDispatcher, diff --git a/src/Action/EditProfileAction.php b/src/Action/EditProfileAction.php index 1a2cb389..7d2487d5 100644 --- a/src/Action/EditProfileAction.php +++ b/src/Action/EditProfileAction.php @@ -32,41 +32,26 @@ final class EditProfileAction { - /** - * @var EventDispatcherInterface - */ - private $eventDispatcher; + private EventDispatcherInterface $eventDispatcher; - /** - * @var FormFactoryInterface - */ - private $formFactory; + private FormFactoryInterface $formFactory; - /** - * @var UserManagerInterface - */ - private $userManager; + private UserManagerInterface $userManager; - /** - * @var Environment - */ - private $twig; + private Environment $twig; - /** - * @var RouterInterface - */ - private $router; + private RouterInterface $router; + + private Security $security; /** - * @var Security + * @phpstan-var class-string */ - private $security; + private string $formModel; /** - * @var string + * @phpstan-param class-string $formModel */ - private $formModel; - public function __construct( EventDispatcherInterface $eventDispatcher, FormFactoryInterface $formFactory, diff --git a/src/Action/RegistrationAction.php b/src/Action/RegistrationAction.php index 18b2af02..2322ff1e 100644 --- a/src/Action/RegistrationAction.php +++ b/src/Action/RegistrationAction.php @@ -30,36 +30,24 @@ final class RegistrationAction { - /** - * @var EventDispatcherInterface - */ - private $eventDispatcher; + private EventDispatcherInterface $eventDispatcher; - /** - * @var FormFactoryInterface - */ - private $formFactory; + private FormFactoryInterface $formFactory; - /** - * @var UserManagerInterface - */ - private $userManager; + private UserManagerInterface $userManager; - /** - * @var Environment - */ - private $twig; + private Environment $twig; + + private RouterInterface $router; /** - * @var RouterInterface + * @phpstan-var class-string */ - private $router; + private string $formModel; /** - * @var string + * @phpstan-param class-string $formModel */ - private $formModel; - public function __construct( EventDispatcherInterface $eventDispatcher, FormFactoryInterface $formFactory, diff --git a/src/Action/RegistrationConfirmedAction.php b/src/Action/RegistrationConfirmedAction.php index 3832eed4..0fbf5999 100644 --- a/src/Action/RegistrationConfirmedAction.php +++ b/src/Action/RegistrationConfirmedAction.php @@ -22,20 +22,11 @@ final class RegistrationConfirmedAction { - /** - * @var Environment - */ - private $twig; + private Environment $twig; - /** - * @var Security - */ - private $security; + private Security $security; - /** - * @var TokenStorageInterface - */ - private $tokenStorage; + private TokenStorageInterface $tokenStorage; public function __construct(Environment $twig, Security $security, TokenStorageInterface $tokenStorage) { diff --git a/src/Action/ShowProfileAction.php b/src/Action/ShowProfileAction.php index 17bec88d..6f52ecfe 100644 --- a/src/Action/ShowProfileAction.php +++ b/src/Action/ShowProfileAction.php @@ -19,15 +19,9 @@ final class ShowProfileAction { - /** - * @var Environment - */ - private $twig; - - /** - * @var Security - */ - private $security; + private Environment $twig; + + private Security $security; public function __construct(Environment $twig, Security $security) { diff --git a/src/Event/GetResponseRegistrationEvent.php b/src/Event/GetResponseRegistrationEvent.php index 446adefa..b287123e 100644 --- a/src/Event/GetResponseRegistrationEvent.php +++ b/src/Event/GetResponseRegistrationEvent.php @@ -18,20 +18,11 @@ class GetResponseRegistrationEvent extends Event { - /** - * @var Request|null - */ - protected $request; + protected ?Request $request; - /** - * @var Registration - */ - protected $registration; + protected Registration $registration; - /** - * @var Response|null - */ - private $response; + private ?Response $response = null; public function __construct(Registration $user, Request $request = null) { @@ -39,7 +30,7 @@ public function __construct(Registration $user, Request $request = null) $this->request = $request; } - public function setResponse(Response $response): void + public function setResponse(?Response $response): void { $this->response = $response; } diff --git a/src/Event/UserFormEvent.php b/src/Event/UserFormEvent.php index 23da1684..8a3ca53b 100644 --- a/src/Event/UserFormEvent.php +++ b/src/Event/UserFormEvent.php @@ -18,14 +18,12 @@ final class UserFormEvent extends FormEvent { - /** - * @var UserInterface - */ - private $user; + private UserInterface $user; public function __construct(UserInterface $user, FormInterface $form, Request $request) { parent::__construct($form, $request); + $this->user = $user; } diff --git a/src/EventListener/AlreadyLoggedinListener.php b/src/EventListener/AlreadyLoggedinListener.php index 212c20d3..c43ef65b 100644 --- a/src/EventListener/AlreadyLoggedinListener.php +++ b/src/EventListener/AlreadyLoggedinListener.php @@ -25,19 +25,10 @@ final class AlreadyLoggedinListener implements EventSubscriberInterface { - /** - * @var Security - */ - private $security; - - /** - * @var RouterInterface - */ - private $router; - - /** - * AlreadyLoggedinListener constructor. - */ + private Security $security; + + private RouterInterface $router; + public function __construct(Security $security, RouterInterface $router) { $this->security = $security; diff --git a/src/EventListener/AuthenticationListener.php b/src/EventListener/AuthenticationListener.php index 024a9b9e..a337c8f0 100644 --- a/src/EventListener/AuthenticationListener.php +++ b/src/EventListener/AuthenticationListener.php @@ -22,15 +22,9 @@ final class AuthenticationListener implements EventSubscriberInterface { - /** - * @var LoginManagerInterface - */ - private $loginManager; + private LoginManagerInterface $loginManager; - /** - * @var string - */ - private $firewallName; + private string $firewallName; public function __construct(LoginManagerInterface $loginManager, string $firewallName) { diff --git a/src/EventListener/EmailConfirmationListener.php b/src/EventListener/EmailConfirmationListener.php index 84c5bf61..aae7cc81 100644 --- a/src/EventListener/EmailConfirmationListener.php +++ b/src/EventListener/EmailConfirmationListener.php @@ -22,25 +22,13 @@ final class EmailConfirmationListener implements EventSubscriberInterface { - /** - * @var MailerInterface - */ - private $mailer; + private MailerInterface $mailer; - /** - * @var TokenGeneratorInterface - */ - private $tokenGenerator; + private TokenGeneratorInterface $tokenGenerator; - /** - * @var UrlGeneratorInterface - */ - private $router; + private UrlGeneratorInterface $router; - /** - * @var SessionInterface - */ - private $session; + private SessionInterface $session; public function __construct( MailerInterface $mailer, diff --git a/src/EventListener/FlashListener.php b/src/EventListener/FlashListener.php index 08eb46b3..e2da4dc8 100644 --- a/src/EventListener/FlashListener.php +++ b/src/EventListener/FlashListener.php @@ -23,20 +23,14 @@ final class FlashListener implements EventSubscriberInterface /** * @var string[] */ - private static $successMessages = [ + private static array $successMessages = [ NucleosProfileEvents::PROFILE_EDIT_COMPLETED => 'profile.flash.updated', NucleosProfileEvents::REGISTRATION_COMPLETED => 'registration.flash.user_created', ]; - /** - * @var FlashBagInterface - */ - private $flashBag; + private FlashBagInterface $flashBag; - /** - * @var TranslatorInterface - */ - private $translator; + private TranslatorInterface $translator; public function __construct(FlashBagInterface $flashBag, TranslatorInterface $translator) { diff --git a/src/Form/Model/Profile.php b/src/Form/Model/Profile.php index b8e95a55..a5d7d12f 100644 --- a/src/Form/Model/Profile.php +++ b/src/Form/Model/Profile.php @@ -16,15 +16,9 @@ class Profile { - /** - * @var string|null - */ - protected $locale; + protected ?string $locale = null; - /** - * @var string|null - */ - protected $timezone; + protected ?string $timezone = null; public static function fromUser(UserInterface $user): self { diff --git a/src/Form/Model/Registration.php b/src/Form/Model/Registration.php index 697d3ea8..2eb564ed 100644 --- a/src/Form/Model/Registration.php +++ b/src/Form/Model/Registration.php @@ -16,20 +16,11 @@ class Registration { - /** - * @var string|null - */ - protected $username; + protected ?string $username = null; - /** - * @var string|null - */ - protected $email; + protected ?string $email = null; - /** - * @var string|null - */ - protected $plainPassword; + protected ?string $plainPassword = null; public function getUsername(): ?string { diff --git a/src/Form/Type/ProfileFormType.php b/src/Form/Type/ProfileFormType.php index 46cb47f5..97ef4edf 100644 --- a/src/Form/Type/ProfileFormType.php +++ b/src/Form/Type/ProfileFormType.php @@ -11,6 +11,7 @@ namespace Nucleos\ProfileBundle\Form\Type; +use Nucleos\ProfileBundle\Form\Model\Profile; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\LocaleType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; @@ -21,12 +22,12 @@ final class ProfileFormType extends AbstractType { /** - * @var string + * @phpstan-var class-string */ - private $class; + private string $class; /** - * @param string $class The User class name + * @phpstan-param class-string $class The User class name */ public function __construct(string $class) { diff --git a/src/Form/Type/RegistrationFormType.php b/src/Form/Type/RegistrationFormType.php index bec77742..67fc25ab 100644 --- a/src/Form/Type/RegistrationFormType.php +++ b/src/Form/Type/RegistrationFormType.php @@ -32,27 +32,18 @@ final class RegistrationFormType extends AbstractType { /** - * @var string + * @phpstan-var class-string */ - private $class; + private string $class; - /** - * @var UserManagerInterface - */ - private $userManager; + private UserManagerInterface $userManager; - /** - * @var ValidatorInterface - */ - private $validator; + private ValidatorInterface $validator; - /** - * @var ViolationMapper - */ - private $violationMapper; + private ViolationMapper $violationMapper; /** - * @param string $class The User class name + * @phpstan-param class-string $class The User class name */ public function __construct(string $class, UserManagerInterface $userManager, ValidatorInterface $validator) { diff --git a/src/Mailer/Mail/RegistrationMail.php b/src/Mailer/Mail/RegistrationMail.php index 5c41151d..9e713ba4 100644 --- a/src/Mailer/Mail/RegistrationMail.php +++ b/src/Mailer/Mail/RegistrationMail.php @@ -18,15 +18,9 @@ final class RegistrationMail extends TemplatedEmail { - /** - * @var string - */ - private $confirmationUrl; + private string $confirmationUrl; - /** - * @var UserInterface - */ - private $user; + private UserInterface $user; public function __construct(Headers $headers = null, AbstractPart $body = null) { diff --git a/src/Mailer/Mailer.php b/src/Mailer/Mailer.php index 9c38bdfa..ef2100c7 100644 --- a/src/Mailer/Mailer.php +++ b/src/Mailer/Mailer.php @@ -21,25 +21,13 @@ final class Mailer implements MailerInterface { - /** - * @var SymfonyMailer - */ - private $mailer; + private SymfonyMailer $mailer; - /** - * @var TranslatorInterface - */ - private $translator; + private TranslatorInterface $translator; - /** - * @var UrlGeneratorInterface - */ - private $router; + private UrlGeneratorInterface $router; - /** - * @var string|null - */ - private $fromEmail; + private ?string $fromEmail; public function __construct( SymfonyMailer $mailer, diff --git a/tests/Action/RegisterActionIntegrationTest.php b/tests/Action/RegisterActionIntegrationTest.php index 8d398454..6a84c958 100644 --- a/tests/Action/RegisterActionIntegrationTest.php +++ b/tests/Action/RegisterActionIntegrationTest.php @@ -19,10 +19,7 @@ final class RegisterActionIntegrationTest extends WebTestCase { - /** - * @var KernelBrowser - */ - private $client; + private KernelBrowser $client; protected function setUp(): void { diff --git a/tests/DependencyInjection/NucleosProfileExtensionTest.php b/tests/DependencyInjection/NucleosProfileExtensionTest.php index f0a59b80..e893a8e5 100644 --- a/tests/DependencyInjection/NucleosProfileExtensionTest.php +++ b/tests/DependencyInjection/NucleosProfileExtensionTest.php @@ -21,10 +21,7 @@ final class NucleosProfileExtensionTest extends TestCase { - /** - * @var ContainerBuilder - */ - protected $configuration; + protected ContainerBuilder $configuration; public function testUserLoadUtilServiceWithDefaults(): void { diff --git a/tests/EventListener/AuthenticationListenerTest.php b/tests/EventListener/AuthenticationListenerTest.php index 3052d77f..29279657 100644 --- a/tests/EventListener/AuthenticationListenerTest.php +++ b/tests/EventListener/AuthenticationListenerTest.php @@ -30,15 +30,9 @@ final class AuthenticationListenerTest extends TestCase */ private $eventDispatcher; - /** - * @var FilterUserResponseEvent - */ - private $event; + private FilterUserResponseEvent $event; - /** - * @var AuthenticationListener - */ - private $listener; + private AuthenticationListener $listener; protected function setUp(): void { diff --git a/tests/EventListener/FlashListenerTest.php b/tests/EventListener/FlashListenerTest.php index 51cdbb0a..f77e06f2 100644 --- a/tests/EventListener/FlashListenerTest.php +++ b/tests/EventListener/FlashListenerTest.php @@ -20,15 +20,9 @@ final class FlashListenerTest extends TestCase { - /** - * @var Event - */ - private $event; - - /** - * @var FlashListener - */ - private $listener; + private Event $event; + + private FlashListener $listener; protected function setUp(): void {