From dae0a915d12df73dcb795c287b43854cd3b89a06 Mon Sep 17 00:00:00 2001 From: Peter Elmered Date: Thu, 12 Sep 2024 21:41:07 +0200 Subject: [PATCH] Code style --- src/Credentials.php | 7 ++++--- src/Options.php | 15 ++++++++------- src/RefreshToken.php | 3 --- tests/Unit/MacroTest.php | 4 ++-- tests/Unit/RefreshTokenTest.php | 2 +- tests/Unit/TokenStoreTest.php | 1 - 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/Credentials.php b/src/Credentials.php index 6458634..d077b6a 100644 --- a/src/Credentials.php +++ b/src/Credentials.php @@ -19,12 +19,13 @@ class Credentials public const AUTH_TYPE_CUSTOM = 'custom'; - public const GRANT_TYPE_CLIENT_CREDENTIALS = 'client_credentials'; + public const GRANT_TYPE_PASSWORD_CREDENTIALS = 'password_credentials'; //TODO: Add support for authorization_code and implicit grants public const GRANT_TYPE_AUTHORIZATION_CODE = 'authorization_code'; + public const GRANT_TYPE_IMPLICIT = 'implicit'; private ?\Closure $customCallback; @@ -52,9 +53,9 @@ public function __construct( //$this->validate(); } - protected function validate( ): void + protected function validate(): void { - Validator::make((array)$this, [ + Validator::make((array) $this, [ 'grantType' => Rule::in([self::GRANT_TYPE_CLIENT_CREDENTIALS, self::GRANT_TYPE_PASSWORD_CREDENTIALS]), 'authType' => Rule::in([self::AUTH_TYPE_BEARER, self::AUTH_TYPE_BODY, self::AUTH_TYPE_QUERY, self::AUTH_TYPE_BASIC, self::AUTH_TYPE_CUSTOM]), ])->validate(); diff --git a/src/Options.php b/src/Options.php index 892c288..bdb6364 100644 --- a/src/Options.php +++ b/src/Options.php @@ -1,4 +1,5 @@ validateOptions(); } @@ -20,9 +21,9 @@ final public function __construct( /** * @param array $options */ - protected function validateOptions( ): void + protected function validateOptions(): void { - Validator::make((array)$this, [ + Validator::make((array) $this, [ 'tokenType' => Rule::in([AccessToken::TYPE_BEARER, AccessToken::TYPE_QUERY, AccessToken::TYPE_CUSTOM]), ])->validate(); } diff --git a/src/RefreshToken.php b/src/RefreshToken.php index 2896b81..0fbf5c2 100644 --- a/src/RefreshToken.php +++ b/src/RefreshToken.php @@ -7,7 +7,6 @@ use Illuminate\Http\Client\PendingRequest; use Illuminate\Http\Client\Response; use Illuminate\Support\Facades\Http; -use Illuminate\Support\Facades\Validator; use InvalidArgumentException; class RefreshToken @@ -62,8 +61,6 @@ public function __invoke( ); } - - protected function resolveRefreshAuth(Credentials $credentials): void { $this->httpClient = $credentials->addAuthToRequest($this->httpClient); diff --git a/tests/Unit/MacroTest.php b/tests/Unit/MacroTest.php index 2dd089f..3bc05bd 100644 --- a/tests/Unit/MacroTest.php +++ b/tests/Unit/MacroTest.php @@ -75,8 +75,8 @@ function (Request $request) { clientSecret: 'this_is_my_client_secret', ), [ - 'scopes' => ['scope1', 'scope2'], - 'tokenType' => AccessToken::TYPE_QUERY + 'scopes' => ['scope1', 'scope2'], + 'tokenType' => AccessToken::TYPE_QUERY, ], )->get('https://example.com/api'); diff --git a/tests/Unit/RefreshTokenTest.php b/tests/Unit/RefreshTokenTest.php index c32c47b..90c6522 100644 --- a/tests/Unit/RefreshTokenTest.php +++ b/tests/Unit/RefreshTokenTest.php @@ -115,7 +115,7 @@ new Credentials([ 'my_client_id', 'my_client_secret', - Credentials::AUTH_TYPE_BODY + Credentials::AUTH_TYPE_BODY, ]), new Options( scopes: ['scope1', 'scope2'], diff --git a/tests/Unit/TokenStoreTest.php b/tests/Unit/TokenStoreTest.php index 23c00f1..635b4a7 100644 --- a/tests/Unit/TokenStoreTest.php +++ b/tests/Unit/TokenStoreTest.php @@ -3,7 +3,6 @@ uses(\Pelmered\LaravelHttpOAuthHelper\Tests\TestCase::class); use Illuminate\Support\Facades\Cache; -use Pelmered\LaravelHttpOAuthHelper\AccessToken; use Pelmered\LaravelHttpOAuthHelper\Credentials; use Pelmered\LaravelHttpOAuthHelper\Options; use Pelmered\LaravelHttpOAuthHelper\TokenStore;