From 5d88d423c50762a6c2255ab0cbeec52772afae14 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Wed, 7 Aug 2024 17:43:34 +0330 Subject: [PATCH] formatting --- src/Http/Controllers/AuthorizationController.php | 15 +++++++-------- tests/Unit/AuthorizationControllerTest.php | 8 +++----- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/Http/Controllers/AuthorizationController.php b/src/Http/Controllers/AuthorizationController.php index 7c12ce94..37bbb9fb 100644 --- a/src/Http/Controllers/AuthorizationController.php +++ b/src/Http/Controllers/AuthorizationController.php @@ -139,14 +139,13 @@ protected function parseScopes($authRequest) */ protected function hasGrantedScopes($user, $client, $scopes) { - return collect($scopes)->pluck('id') - ->diff($user->tokens() - ->where('client_id', $client->getKey()) - ->where('revoked', false) - ->where('expires_at', '>', Date::now()) - ->pluck('scopes') - ->flatten() - )->isEmpty(); + return collect($scopes)->pluck('id')->diff( + $user->tokens()->where([ + ['client_id', '=', $client->getKey()], + ['revoked', '=', false], + ['expires_at', '>', Date::now()], + ])->pluck('scopes')->flatten() + )->isEmpty(); } /** diff --git a/tests/Unit/AuthorizationControllerTest.php b/tests/Unit/AuthorizationControllerTest.php index fb648c73..3ebeed5a 100644 --- a/tests/Unit/AuthorizationControllerTest.php +++ b/tests/Unit/AuthorizationControllerTest.php @@ -61,7 +61,7 @@ public function test_authorization_view_is_presented() $client->shouldReceive('skipsAuthorization')->andReturn(false); $client->shouldReceive('getKey')->andReturn(1); - $user->shouldReceive('tokens->where->where->where->pluck->flatten')->andReturn(collect()); + $user->shouldReceive('tokens->where->pluck->flatten')->andReturn(collect()); $response->shouldReceive('withParameters')->once()->andReturnUsing(function ($data) use ($client, $user, $request) { $this->assertEquals($client, $data['client']); @@ -140,7 +140,7 @@ public function test_request_is_approved_if_valid_token_exists() $client->shouldReceive('skipsAuthorization')->andReturn(false); $client->shouldReceive('getKey')->andReturn(1); - $user->shouldReceive('tokens->where->where->where->pluck->flatten')->andReturn(collect(['scope-1'])); + $user->shouldReceive('tokens->where->pluck->flatten')->andReturn(collect(['scope-1'])); $this->assertSame('approved', $controller->authorize( m::mock(ServerRequestInterface::class), $request, $clients @@ -186,8 +186,6 @@ public function test_request_is_approved_if_client_can_skip_authorization() $client->shouldReceive('skipsAuthorization')->andReturn(true); - $user->shouldReceive('tokens->where->where->where->pluck->flatten')->andReturn(collect()); - $this->assertSame('approved', $controller->authorize( m::mock(ServerRequestInterface::class), $request, $clients )->getContent()); @@ -279,7 +277,7 @@ public function test_authorization_denied_if_request_has_prompt_equals_to_none() $client->shouldReceive('skipsAuthorization')->andReturn(false); $client->shouldReceive('getKey')->andReturn(1); - $user->shouldReceive('tokens->where->where->where->pluck->flatten')->andReturn(collect()); + $user->shouldReceive('tokens->where->pluck->flatten')->andReturn(collect()); $controller->authorize( m::mock(ServerRequestInterface::class), $request, $clients