Skip to content

Commit c2bfa32

Browse files
seb-jeanjrushlow
andauthored
feature #1548 [make:reset-password] improve generated typehints for phpstan
* Update ResetPasswordController.tpl.php * fix expected generated code for changes --------- Co-authored-by: Jesse Rushlow <[email protected]>
1 parent b8707f1 commit c2bfa32

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

src/Resources/skeleton/resetPassword/ResetPasswordController.tpl.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ public function request(Request $request, MailerInterface $mailer<?php if ($tran
2525
$form->handleRequest($request);
2626

2727
if ($form->isSubmitted() && $form->isValid()) {
28-
return $this->processSendingPasswordResetEmail(
29-
$form->get('<?= $email_field ?>')->getData(),
30-
$mailer<?php if ($translator_available): ?>,
31-
$translator<?php endif ?><?= "\n" ?>
32-
);
28+
/** @var string $email */
29+
$email = $form->get('<?= $email_field ?>')->getData();
30+
31+
return $this->processSendingPasswordResetEmail($email, $mailer<?php if ($translator_available): ?>, $translator<?php endif ?><?= "\n" ?>);
3332
}
3433

3534
return $this->render('reset_password/request.html.twig', [
@@ -94,13 +93,11 @@ public function reset(Request $request, UserPasswordHasherInterface $passwordHas
9493
// A password reset token should be used only once, remove it.
9594
$this->resetPasswordHelper->removeResetRequest($token);
9695

97-
// Encode(hash) the plain password, and set it.
98-
$encodedPassword = $passwordHasher->hashPassword(
99-
$user,
100-
$form->get('plainPassword')->getData()
101-
);
96+
/** @var string $plainPassword */
97+
$plainPassword = $form->get('plainPassword')->getData();
10298

103-
$user-><?= $password_setter ?>($encodedPassword);
99+
// Encode(hash) the plain password, and set it.
100+
$user-><?= $password_setter ?>($passwordHasher->hashPassword($user, $plainPassword));
104101
$this->entityManager->flush();
105102

106103
// The session is cleaned up after the password has been changed.
@@ -143,7 +140,7 @@ private function processSendingPasswordResetEmail(string $emailFormData, MailerI
143140

144141
$email = (new TemplatedEmail())
145142
->from(new Address('<?= $from_email ?>', '<?= $from_email_name ?>'))
146-
->to($user-><?= $email_getter ?>())
143+
->to((string) $user-><?= $email_getter ?>())
147144
->subject('Your password reset request')
148145
->htmlTemplate('reset_password/email.html.twig')
149146
->context([

tests/Maker/MakeResetPasswordTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ public function getTestDetails(): \Generator
352352
$contentResetPasswordController = file_get_contents($runner->getPath('src/Controller/ResetPasswordController.php'));
353353
$this->assertStringContainsString('$form->get(\'emailAddress\')->getData()', $contentResetPasswordController);
354354
$this->assertStringContainsString('\'emailAddress\' => $emailFormData,', $contentResetPasswordController);
355-
$this->assertStringContainsString('$user->setMyPassword($encodedPassword);', $contentResetPasswordController);
356-
$this->assertStringContainsString('->to($user->getEmailAddress())', $contentResetPasswordController);
355+
$this->assertStringContainsString('$user->setMyPassword($passwordHasher->hashPassword($user, $plainPassword));', $contentResetPasswordController);
356+
$this->assertStringContainsString('->to((string) $user->getEmailAddress())', $contentResetPasswordController);
357357

358358
// check ResetPasswordRequest
359359
$contentResetPasswordRequest = file_get_contents($runner->getPath('src/Entity/ResetPasswordRequest.php'));

0 commit comments

Comments
 (0)