Skip to content
This repository was archived by the owner on Oct 15, 2025. It is now read-only.

Commit a9158eb

Browse files
committed
fix(entity): Explicit "PasswordSettableUserInterface"
1 parent 395730f commit a9158eb

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Repository;
6+
7+
interface PasswordSettableUserInterface
8+
{
9+
public function setPassword(string $password): void;
10+
}

src/Repository/UserRepository.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public function __construct(ManagerRegistry $registry)
2727
*/
2828
public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void
2929
{
30+
if (!$user instanceof PasswordSettableUserInterface) {
31+
throw new \InvalidArgumentException(\sprintf('User must implement %s in order to be upgraded.', PasswordSettableUserInterface::class));
32+
}
33+
3034
$user->setPassword($newHashedPassword);
3135
$this->getEntityManager()->persist($user);
3236
$this->getEntityManager()->flush();

0 commit comments

Comments
 (0)