Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 committed Feb 10, 2022
1 parent 8f130bf commit b41f0e4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
12 changes: 10 additions & 2 deletions src/Document/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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<UserInterface> $class
*
Expand All @@ -50,6 +53,7 @@ public function __construct(
string $class,
ManagerRegistry $registry,
CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater,
// @phpstan-ignore-next-line
object $userPasswordHasher
) {
parent::__construct($class, $registry);
Expand All @@ -58,6 +62,9 @@ public function __construct(
$this->userPasswordHasher = $userPasswordHasher;
}

/**
* @psalm-suppress UndefinedDocblockClass
*/
public function updatePassword(UserInterface $user): void
{
$plainPassword = $user->getPlainPassword();
Expand All @@ -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);
}

Expand Down
12 changes: 10 additions & 2 deletions src/Entity/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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<UserInterface> $class
*
Expand All @@ -50,6 +53,7 @@ public function __construct(
string $class,
ManagerRegistry $registry,
CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater,
// @phpstan-ignore-next-line
object $userPasswordHasher
) {
parent::__construct($class, $registry);
Expand All @@ -58,6 +62,9 @@ public function __construct(
$this->userPasswordHasher = $userPasswordHasher;
}

/**
* @psalm-suppress UndefinedDocblockClass
*/
public function updatePassword(UserInterface $user): void
{
$plainPassword = $user->getPlainPassword();
Expand All @@ -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);
}

Expand Down
7 changes: 4 additions & 3 deletions src/Security/UserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 2 additions & 0 deletions tests/Security/UserProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b41f0e4

Please sign in to comment.