From fb8f2fa9f2e3c9c50a74651b44c10f83f967825a Mon Sep 17 00:00:00 2001 From: Artem Vasilev Date: Tue, 12 Mar 2024 23:08:37 +0300 Subject: [PATCH] Update php doc and properties types --- .../src/Repository/AuthCodeRepository.php | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/com_oauthserver/site/src/Repository/AuthCodeRepository.php b/com_oauthserver/site/src/Repository/AuthCodeRepository.php index cd1dce3..4382831 100644 --- a/com_oauthserver/site/src/Repository/AuthCodeRepository.php +++ b/com_oauthserver/site/src/Repository/AuthCodeRepository.php @@ -41,31 +41,31 @@ class AuthCodeRepository implements AuthCodeRepositoryInterface return new AuthCode(); } - public function persistNewAuthCode(AuthCodeEntityInterface $authCodeEntity) + /** + * @param AuthCodeEntityInterface $authCodeEntity + * + * @return void + * @throws UniqueTokenIdentifierConstraintViolationException + * @throws \Exception + * @since version + */ + public function persistNewAuthCode(AuthCodeEntityInterface $authCodeEntity): void { - $found = false; - try - { - $authCode = $this->authCodeModel->getItemByIdentifier($authCodeEntity->getIdentifier()); + $authCode = $this->authCodeModel->getItemByIdentifier($authCodeEntity->getIdentifier()); - if ($authCode->id > 0) - { - $found = true; - - } - } - catch (\Throwable $e) - { - } - - if ($found) + if ($authCode !== false) { throw UniqueTokenIdentifierConstraintViolationException::create(); } $data = $authCodeEntity->getData(); - $client = $this->clientModel->getItemByIdentifier($authCodeEntity->getClient()->getIdentifier()); + $client = $this->clientModel->getItemByIdentifier($data['client_identifier']); + + if ($client === false) + { + throw new \RuntimeException($this->clientModel->getError()); + } $data['client_id'] = $client->id; unset($data['client_identifier']); @@ -73,20 +73,27 @@ class AuthCodeRepository implements AuthCodeRepositoryInterface $this->authCodeModel->save($data); } - public function revokeAuthCode($codeId) + public function revokeAuthCode($codeId): void { $this->authCodeModel->revoke($codeId); } - public function isAuthCodeRevoked($codeId) + /** + * @param string $codeId + * + * @throws \Exception + * @since version + * @noinspection PhpPossiblePolymorphicInvocationInspection + */ + public function isAuthCodeRevoked($codeId): bool { $authCode = $this->authCodeModel->getItemByIdentifier($codeId); - if (empty($authCode->id)) + if ($authCode === false) { return true; } - return !!$authCode->revoked; + return (bool) $authCode->revoked; } }