Update php doc and properties types

This commit is contained in:
Artem Vasilev 2024-03-12 23:14:08 +03:00
parent e8727b787c
commit 665f4ac2d4

View File

@ -43,30 +43,31 @@ class RefreshTokenRepository implements RefreshTokenRepositoryInterface
return new RefreshToken(); return new RefreshToken();
} }
public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshTokenEntity) /**
{ * @param RefreshTokenEntityInterface $refreshTokenEntity
$found = false; *
try * @return void
* @throws UniqueTokenIdentifierConstraintViolationException
* @throws \Exception
* @since version
*/
public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshTokenEntity): void
{ {
$refreshToken = $this->refreshTokenModel->getItemByIdentifier($refreshTokenEntity->getIdentifier()); $refreshToken = $this->refreshTokenModel->getItemByIdentifier($refreshTokenEntity->getIdentifier());
if ($refreshToken->id > 0) if ($refreshToken !== false)
{
$found = true;
}
}
catch (\Exception $e)
{
}
if ($found)
{ {
throw UniqueTokenIdentifierConstraintViolationException::create(); throw UniqueTokenIdentifierConstraintViolationException::create();
} }
$data = $refreshTokenEntity->getData(); $data = $refreshTokenEntity->getData();
$accessToken = $this->accessTokenModel->getItemByIdentifier($refreshTokenEntity->getAccessToken()->getIdentifier()); $accessToken = $this->accessTokenModel->getItemByIdentifier($data['access_token_identifier']);
if ($accessToken === false)
{
throw new \RuntimeException($this->accessTokenModel->getError());
}
unset($data['access_token_identifier']); unset($data['access_token_identifier']);
$data['access_token_id'] = $accessToken->id; $data['access_token_id'] = $accessToken->id;
@ -79,15 +80,22 @@ class RefreshTokenRepository implements RefreshTokenRepositoryInterface
$this->refreshTokenModel->revoke($tokenId); $this->refreshTokenModel->revoke($tokenId);
} }
/**
* @param string $tokenId
*
* @throws \Exception
* @since version
* @noinspection PhpPossiblePolymorphicInvocationInspection
*/
public function isRefreshTokenRevoked($tokenId): bool public function isRefreshTokenRevoked($tokenId): bool
{ {
$refreshToken = $this->refreshTokenModel->getItemByIdentifier($tokenId); $refreshToken = $this->refreshTokenModel->getItemByIdentifier($tokenId);
if (empty($refreshToken->id)) if ($refreshToken === false)
{ {
return true; return true;
} }
return !!$refreshToken->revoked; return (bool) $refreshToken->revoked;
} }
} }