From bec9511aa71f3563fee3f0b222270b4c2fac7818 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Tue, 2 Apr 2024 16:36:33 -0400 Subject: [PATCH] [make:registration] add missing property types --- src/Maker/MakeRegistrationForm.php | 51 ++++++++++++++++-------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/src/Maker/MakeRegistrationForm.php b/src/Maker/MakeRegistrationForm.php index ed34a5f53..ac69a1ff3 100644 --- a/src/Maker/MakeRegistrationForm.php +++ b/src/Maker/MakeRegistrationForm.php @@ -68,18 +68,18 @@ */ final class MakeRegistrationForm extends AbstractMaker { - private $userClass; - private $usernameField; - private $passwordField; - private $willVerifyEmail = false; - private $verifyEmailAnonymously = false; - private $idGetter; - private $emailGetter; - private $fromEmailAddress; - private $fromEmailName; + private string $userClass; + private string $usernameField; + private string $passwordField; + private bool $willVerifyEmail = false; + private bool $verifyEmailAnonymously = false; + private string $idGetter; + private string $emailGetter; + private string $fromEmailAddress; + private string $fromEmailName; private ?Authenticator $autoLoginAuthenticator = null; - private $redirectRouteName; - private $addUniqueEntityConstraint; + private string $redirectRouteName; + private bool $addUniqueEntityConstraint = false; public function __construct( private FileManager $fileManager, @@ -99,7 +99,7 @@ public static function getCommandDescription(): string return 'Create a new registration form system'; } - public function configureCommand(Command $command, InputConfiguration $inputConf): void + public function configureCommand(Command $command, InputConfiguration $inputConfig): void { $command ->setHelp(file_get_contents(__DIR__.'/../Resources/help/MakeRegistrationForm.txt')) @@ -135,13 +135,12 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma // see if it makes sense to add the UniqueEntity constraint $userClassDetails = new ClassDetails($this->userClass); - $this->addUniqueEntityConstraint = false; if (!$userClassDetails->hasAttribute(UniqueEntity::class)) { - $this->addUniqueEntityConstraint = $io->confirm(sprintf('Do you want to add a #[UniqueEntity] validation attribute to your %s class to make sure duplicate accounts aren\'t created?', Str::getShortClassName($this->userClass))); + $this->addUniqueEntityConstraint = (bool) $io->confirm(sprintf('Do you want to add a #[UniqueEntity] validation attribute to your %s class to make sure duplicate accounts aren\'t created?', Str::getShortClassName($this->userClass))); } - $this->willVerifyEmail = $io->confirm('Do you want to send an email to verify the user\'s email address after registration?', true); + $this->willVerifyEmail = (bool) $io->confirm('Do you want to send an email to verify the user\'s email address after registration?'); if ($this->willVerifyEmail) { $this->checkComponentsExist($io); @@ -151,7 +150,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma $emailText[] = 'having to log in. To allow multi device email verification, we can embed a user id in the verification link.'; $io->text($emailText); $io->newLine(); - $this->verifyEmailAnonymously = $io->confirm('Would you like to include the user id in the verification link to allow anonymous email verification?', false); + $this->verifyEmailAnonymously = (bool) $io->confirm('Would you like to include the user id in the verification link to allow anonymous email verification?', false); $this->idGetter = $interactiveSecurityHelper->guessIdGetter($io, $this->userClass); $this->emailGetter = $interactiveSecurityHelper->guessEmailGetter($io, $this->userClass, 'email'); @@ -233,7 +232,18 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen 'Security\\' ); + $verifyEmailVars = ['will_verify_email' => $this->willVerifyEmail]; + if ($this->willVerifyEmail) { + $verifyEmailVars = [ + 'will_verify_email' => $this->willVerifyEmail, + 'email_verifier_class_details' => $verifyEmailServiceClassNameDetails, + 'verify_email_anonymously' => $this->verifyEmailAnonymously, + 'from_email' => $this->fromEmailAddress, + 'from_email_name' => addslashes($this->fromEmailName), + 'email_getter' => $this->emailGetter, + ]; + $useStatements = new UseStatementGenerator([ EntityManagerInterface::class, TemplatedEmail::class, @@ -333,17 +343,12 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen 'form_class_name' => $formClassDetails->getShortName(), 'user_class_name' => $userClassNameDetails->getShortName(), 'password_field' => $this->passwordField, - 'will_verify_email' => $this->willVerifyEmail, - 'email_verifier_class_details' => $verifyEmailServiceClassNameDetails, - 'verify_email_anonymously' => $this->verifyEmailAnonymously, - 'from_email' => $this->fromEmailAddress, - 'from_email_name' => addslashes($this->fromEmailName), - 'email_getter' => $this->emailGetter, - 'redirect_route_name' => $this->redirectRouteName, + 'redirect_route_name' => $this->redirectRouteName ?? null, 'translator_available' => $isTranslatorAvailable, ], $userRepoVars, $autoLoginVars, + $verifyEmailVars, ) );