From b41f0e41fed902703dd43c88ef23de97299961be Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 10 Feb 2022 08:46:22 +0100 Subject: [PATCH] Fix build --- src/Document/UserManager.php | 12 ++++++++++-- src/Entity/UserManager.php | 12 ++++++++++-- src/Security/UserProvider.php | 7 ++++--- tests/Security/UserProviderTest.php | 2 ++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/Document/UserManager.php b/src/Document/UserManager.php index 568939c04..3134d24ea 100644 --- a/src/Document/UserManager.php +++ b/src/Document/UserManager.php @@ -31,7 +31,10 @@ final class UserManager extends BaseDocumentManager implements UserManagerInterf private CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater; /** - * @psalm-suppress DeprecatedClass + * TODO: Simplify this once support for Symfony 4.4 is dropped. + * + * @psalm-suppress UndefinedDocblockClass + * @phpstan-ignore-next-line * * @var UserPasswordEncoderInterface|UserPasswordHasherInterface */ @@ -40,7 +43,7 @@ final class UserManager extends BaseDocumentManager implements UserManagerInterf /** * TODO: Simplify this once support for Symfony 4.4 is dropped. * - * @psalm-suppress DeprecatedClass + * @psalm-suppress UndefinedDocblockClass * * @phpstan-param class-string $class * @@ -50,6 +53,7 @@ public function __construct( string $class, ManagerRegistry $registry, CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater, + // @phpstan-ignore-next-line object $userPasswordHasher ) { parent::__construct($class, $registry); @@ -58,6 +62,9 @@ public function __construct( $this->userPasswordHasher = $userPasswordHasher; } + /** + * @psalm-suppress UndefinedDocblockClass + */ public function updatePassword(UserInterface $user): void { $plainPassword = $user->getPlainPassword(); @@ -69,6 +76,7 @@ public function updatePassword(UserInterface $user): void if ($this->userPasswordHasher instanceof UserPasswordHasherInterface) { $password = $this->userPasswordHasher->hashPassword($user, $plainPassword); } else { + // @phpstan-ignore-next-line $password = $this->userPasswordHasher->encodePassword($user, $plainPassword); } diff --git a/src/Entity/UserManager.php b/src/Entity/UserManager.php index 53d906746..5af3cba1a 100644 --- a/src/Entity/UserManager.php +++ b/src/Entity/UserManager.php @@ -31,7 +31,10 @@ final class UserManager extends BaseEntityManager implements UserManagerInterfac private CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater; /** - * @psalm-suppress DeprecatedClass + * TODO: Simplify this once support for Symfony 4.4 is dropped. + * + * @psalm-suppress UndefinedDocblockClass + * @phpstan-ignore-next-line * * @var UserPasswordEncoderInterface|UserPasswordHasherInterface */ @@ -40,7 +43,7 @@ final class UserManager extends BaseEntityManager implements UserManagerInterfac /** * TODO: Simplify this once support for Symfony 4.4 is dropped. * - * @psalm-suppress DeprecatedClass + * @psalm-suppress UndefinedDocblockClass * * @phpstan-param class-string $class * @@ -50,6 +53,7 @@ public function __construct( string $class, ManagerRegistry $registry, CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater, + // @phpstan-ignore-next-line object $userPasswordHasher ) { parent::__construct($class, $registry); @@ -58,6 +62,9 @@ public function __construct( $this->userPasswordHasher = $userPasswordHasher; } + /** + * @psalm-suppress UndefinedDocblockClass + */ public function updatePassword(UserInterface $user): void { $plainPassword = $user->getPlainPassword(); @@ -69,6 +76,7 @@ public function updatePassword(UserInterface $user): void if ($this->userPasswordHasher instanceof UserPasswordHasherInterface) { $password = $this->userPasswordHasher->hashPassword($user, $plainPassword); } else { + // @phpstan-ignore-next-line $password = $this->userPasswordHasher->encodePassword($user, $plainPassword); } diff --git a/src/Security/UserProvider.php b/src/Security/UserProvider.php index c476fe5f7..cac2ee137 100644 --- a/src/Security/UserProvider.php +++ b/src/Security/UserProvider.php @@ -39,12 +39,12 @@ public function loadUserByUsername($username): SecurityUserInterface return $this->loadUserByIdentifier($username); } - public function loadUserByIdentifier(string $username): SecurityUserInterface + public function loadUserByIdentifier(string $identifier): SecurityUserInterface { - $user = $this->findUser($username); + $user = $this->findUser($identifier); if (null === $user || !$user->isEnabled()) { - throw $this->buildUserNotFoundException(sprintf('Username "%s" does not exist.', $username)); + throw $this->buildUserNotFoundException(sprintf('Username "%s" does not exist.', $identifier)); } return $user; @@ -90,6 +90,7 @@ private function findUser(string $username): ?UserInterface private function buildUserNotFoundException(string $message): AuthenticationException { if (!class_exists(UserNotFoundException::class)) { + // @phpstan-ignore-next-line return new UsernameNotFoundException($message); } diff --git a/tests/Security/UserProviderTest.php b/tests/Security/UserProviderTest.php index 3b11e7192..605727f7b 100644 --- a/tests/Security/UserProviderTest.php +++ b/tests/Security/UserProviderTest.php @@ -62,6 +62,7 @@ public function testLoadUserByInvalidUsername(): void { $this->userManager->expects(static::once())->method('findUserByUsernameOrEmail'); + // @phpstan-ignore-next-line $this->expectException(class_exists(UserNotFoundException::class) ? UserNotFoundException::class : UsernameNotFoundException::class); $this->userProvider->loadUserByUsername('foobar'); @@ -99,6 +100,7 @@ public function testRefreshDeleted(): void ->method('getClass') ->willReturn(\get_class($user)); + // @phpstan-ignore-next-line $this->expectException(class_exists(UserNotFoundException::class) ? UserNotFoundException::class : UsernameNotFoundException::class); $this->userProvider->refreshUser($user);