Skip to content

[make:reset-password] improve generated typehints for phpstan #1548

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

Merged
merged 2 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
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
Loading