Skip to content

Commit

Permalink
feature #1548 [make:reset-password] improve generated typehints for p…
Browse files Browse the repository at this point in the history
…hpstan

* Update ResetPasswordController.tpl.php

* fix expected generated code for changes

---------

Co-authored-by: Jesse Rushlow <jr@rushlow.dev>
  • Loading branch information
seb-jean and jrushlow authored Jun 17, 2024
1 parent b8707f1 commit c2bfa32
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ public function request(Request $request, MailerInterface $mailer<?php if ($tran
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
return $this->processSendingPasswordResetEmail(
$form->get('<?= $email_field ?>')->getData(),
$mailer<?php if ($translator_available): ?>,
$translator<?php endif ?><?= "\n" ?>
);
/** @var string $email */
$email = $form->get('<?= $email_field ?>')->getData();

return $this->processSendingPasswordResetEmail($email, $mailer<?php if ($translator_available): ?>, $translator<?php endif ?><?= "\n" ?>);
}

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

// Encode(hash) the plain password, and set it.
$encodedPassword = $passwordHasher->hashPassword(
$user,
$form->get('plainPassword')->getData()
);
/** @var string $plainPassword */
$plainPassword = $form->get('plainPassword')->getData();

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

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

$email = (new TemplatedEmail())
->from(new Address('<?= $from_email ?>', '<?= $from_email_name ?>'))
->to($user-><?= $email_getter ?>())
->to((string) $user-><?= $email_getter ?>())
->subject('Your password reset request')
->htmlTemplate('reset_password/email.html.twig')
->context([
Expand Down
4 changes: 2 additions & 2 deletions tests/Maker/MakeResetPasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ public function getTestDetails(): \Generator
$contentResetPasswordController = file_get_contents($runner->getPath('src/Controller/ResetPasswordController.php'));
$this->assertStringContainsString('$form->get(\'emailAddress\')->getData()', $contentResetPasswordController);
$this->assertStringContainsString('\'emailAddress\' => $emailFormData,', $contentResetPasswordController);
$this->assertStringContainsString('$user->setMyPassword($encodedPassword);', $contentResetPasswordController);
$this->assertStringContainsString('->to($user->getEmailAddress())', $contentResetPasswordController);
$this->assertStringContainsString('$user->setMyPassword($passwordHasher->hashPassword($user, $plainPassword));', $contentResetPasswordController);
$this->assertStringContainsString('->to((string) $user->getEmailAddress())', $contentResetPasswordController);

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

0 comments on commit c2bfa32

Please sign in to comment.