From 383bd13c64ce2c79e174fd4d7800f8379e3fbfde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=B8=9C=E4=BA=91?= Date: Mon, 19 Jun 2023 10:50:07 +0800 Subject: [PATCH] style: lint --- src/Services/AppAuthentication.php | 10 ++-------- src/Services/JwtAuthentication.php | 11 ++++------- src/Traits/LoginRequired.php | 5 +---- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/Services/AppAuthentication.php b/src/Services/AppAuthentication.php index 95d5043..cb765d6 100644 --- a/src/Services/AppAuthentication.php +++ b/src/Services/AppAuthentication.php @@ -25,16 +25,10 @@ class AppAuthentication implements AuthenticationInterface private $user; - /** - * @Inject() - * @var RequestInterface - */ + #[Inject] private RequestInterface $request; - /** - * @Inject() - * @var Redis - */ + #[Inject] private Redis $redis; public function __construct() diff --git a/src/Services/JwtAuthentication.php b/src/Services/JwtAuthentication.php index 26557ee..724ad2d 100644 --- a/src/Services/JwtAuthentication.php +++ b/src/Services/JwtAuthentication.php @@ -39,11 +39,8 @@ class JwtAuthentication implements AuthenticationInterface { use JustDont; use CannotInvalid; - - /** - * @Inject() - * @var \Hyperf\HttpServer\Contract\RequestInterface - */ + + #[Inject] private RequestInterface $request; public function generate(User $user): string @@ -90,7 +87,7 @@ class JwtAuthentication implements AuthenticationInterface throw new Unauthorized($error_code, $exception); } if (empty($decoded)) { - throw new ValidateException(CommonErrorCode::AUTH_JWT_ERROR, 'token', $decoded); + throw new ValidateException(CommonErrorCode::AUTH_JWT_ERROR, 'token', currentValue: $decoded); } // 判断签发机构 @@ -169,7 +166,7 @@ class JwtAuthentication implements AuthenticationInterface /** @var \Singularity\HDK\Auth\Resource\JsonWebToken $currentUser */ $currentUser = Context::get('jwt'); if (empty($currentUser)) { - throw new Unauthorized(RFC7616::DIGEST); + throw new Unauthorized(); } if (isset($column)) { diff --git a/src/Traits/LoginRequired.php b/src/Traits/LoginRequired.php index f10c87e..1565852 100644 --- a/src/Traits/LoginRequired.php +++ b/src/Traits/LoginRequired.php @@ -24,10 +24,7 @@ use Singularity\HDK\Auth\Services\AuthenticationInterface; */ trait LoginRequired { - /** - * @Inject() - * @var AuthenticationInterface - */ + #[Inject] private AuthenticationInterface $authentication; public function authorize(): bool {