Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[make:registration-form] improve generated types for phpstan #1549

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/Resources/skeleton/registration/RegistrationController.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ public function register(Request $request, UserPasswordHasherInterface $userPass
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
/** @var string $plainPassword */
$plainPassword = $form->get('plainPassword')->getData();

// encode the plain password
$user->set<?= ucfirst($password_field) ?>(
$userPasswordHasher->hashPassword(
$user,
$form->get('plainPassword')->getData()
)
);
$user->set<?= ucfirst($password_field) ?>($userPasswordHasher->hashPassword($user, $plainPassword));

$entityManager->persist($user);
$entityManager->flush();
Expand All @@ -36,7 +34,7 @@ public function register(Request $request, UserPasswordHasherInterface $userPass
$this->emailVerifier->sendEmailConfirmation('app_verify_email', $user,
(new TemplatedEmail())
->from(new Address('<?= $from_email ?>', '<?= $from_email_name ?>'))
->to($user-><?= $email_getter ?>())
->to((string) $user-><?= $email_getter ?>())
->subject('Please Confirm your Email')
->htmlTemplate('registration/confirmation_email.html.twig')
);
Expand Down Expand Up @@ -84,7 +82,11 @@ public function verifyUserEmail(Request $request<?php if ($translator_available)

// validate email confirmation link, sets User::isVerified=true and persists
try {
$this->emailVerifier->handleEmailConfirmation($request, <?= $verify_email_anonymously ? '$user' : '$this->getUser()' ?>);
<?php if (!$verify_email_anonymously): ?>
/** @var <?= $user_class_name ?> $user */
$user = $this->getUser();
<?php endif; ?>
$this->emailVerifier->handleEmailConfirmation($request, $user);
} catch (VerifyEmailExceptionInterface $exception) {
$this->addFlash('verify_email_error', <?php if ($translator_available): ?>$translator->trans($exception->getReason(), [], 'VerifyEmailBundle')<?php else: ?>$exception->getReason()<?php endif ?>);

Expand Down
6 changes: 3 additions & 3 deletions src/Resources/skeleton/verifyEmail/EmailVerifier.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public function sendEmailConfirmation(string $verifyEmailRouteName, <?= $user_cl
$verifyEmailRouteName,
(string) $user-><?= $id_getter ?>(),
<?php if ($verify_email_anonymously): ?>
$user-><?= $email_getter ?>(),
(string) $user-><?= $email_getter ?>(),
['id' => $user-><?= $id_getter ?>()]
<?php else: ?>
$user-><?= $email_getter ?>()
(string) $user-><?= $email_getter ?>()
<?php endif; ?>
);

Expand All @@ -41,7 +41,7 @@ public function sendEmailConfirmation(string $verifyEmailRouteName, <?= $user_cl
*/
public function handleEmailConfirmation(Request $request, <?= $user_class_name ?> $user): void
{
$this->verifyEmailHelper->validateEmailConfirmationFromRequest($request, (string) $user-><?= $id_getter ?>(), $user-><?= $email_getter?>());
$this->verifyEmailHelper->validateEmailConfirmationFromRequest($request, (string) $user-><?= $id_getter ?>(), (string) $user-><?= $email_getter?>());

$user->setVerified(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ public function register(Request $request, UserPasswordHasherInterface $userPass
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
/** @var string $plainPassword */
$plainPassword = $form->get('plainPassword')->getData();

// encode the plain password
$user->setPassword(
$userPasswordHasher->hashPassword(
$user,
$form->get('plainPassword')->getData()
)
);
$user->setPassword($userPasswordHasher->hashPassword($user, $plainPassword));

$entityManager->persist($user);
$entityManager->flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ public function register(Request $request, UserPasswordHasherInterface $userPass
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
/** @var string $plainPassword */
$plainPassword = $form->get('plainPassword')->getData();

// encode the plain password
$user->setPassword(
$userPasswordHasher->hashPassword(
$user,
$form->get('plainPassword')->getData()
)
);
$user->setPassword($userPasswordHasher->hashPassword($user, $plainPassword));

$entityManager->persist($user);
$entityManager->flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ public function register(Request $request, UserPasswordHasherInterface $userPass
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
/** @var string $plainPassword */
$plainPassword = $form->get('plainPassword')->getData();

// encode the plain password
$user->setPassword(
$userPasswordHasher->hashPassword(
$user,
$form->get('plainPassword')->getData()
)
);
$user->setPassword($userPasswordHasher->hashPassword($user, $plainPassword));

$entityManager->persist($user);
$entityManager->flush();
Expand Down
Loading