diff --git a/src/Contracts/AuthorizationViewResponse.php b/src/Contracts/AuthorizationViewResponse.php index 6594c6624..54369be63 100644 --- a/src/Contracts/AuthorizationViewResponse.php +++ b/src/Contracts/AuthorizationViewResponse.php @@ -9,8 +9,7 @@ interface AuthorizationViewResponse extends Responsable /** * Specify the parameters that should be passed to the view. * - * @param array $parameters - * @return $this + * @param array $parameters */ - public function withParameters($parameters = []); + public function withParameters(array $parameters = []): static; } diff --git a/src/Http/Responses/SimpleViewResponse.php b/src/Http/Responses/SimpleViewResponse.php index 561bedc7b..7d1335d19 100644 --- a/src/Http/Responses/SimpleViewResponse.php +++ b/src/Http/Responses/SimpleViewResponse.php @@ -2,43 +2,32 @@ namespace Laravel\Passport\Http\Responses; +use Closure; use Illuminate\Contracts\Support\Responsable; use Laravel\Passport\Contracts\AuthorizationViewResponse; class SimpleViewResponse implements AuthorizationViewResponse { - /** - * The name of the view or the callable used to generate the view. - * - * @var callable|string - */ - protected $view; - /** * An array of arguments that may be passed to the view response and used in the view. * - * @var array + * @var array */ - protected $parameters; + protected array $parameters = []; /** * Create a new response instance. - * - * @param callable|string $view - * @return void */ - public function __construct($view) + public function __construct(protected Closure|string $view) { - $this->view = $view; } /** * Add parameters to response. * - * @param array $parameters - * @return $this + * @param array $parameters */ - public function withParameters($parameters = []) + public function withParameters(array $parameters = []): static { $this->parameters = $parameters; diff --git a/tests/Unit/AuthorizationControllerTest.php b/tests/Unit/AuthorizationControllerTest.php index eafc16cf7..cb925834a 100644 --- a/tests/Unit/AuthorizationControllerTest.php +++ b/tests/Unit/AuthorizationControllerTest.php @@ -63,16 +63,16 @@ public function test_authorization_view_is_presented() $user->shouldReceive('getAuthIdentifier')->andReturn(1); - $response->shouldReceive('withParameters')->once()->andReturnUsing(function ($data) use ($client, $user, $request) { + $response->shouldReceive('withParameters')->once()->andReturnUsing(function ($data) use ($client, $user, $request, $response) { $this->assertEquals($client, $data['client']); $this->assertEquals($user, $data['user']); $this->assertEquals($request, $data['request']); $this->assertSame('description', $data['scopes'][0]->description); - return 'view'; + return $response; }); - $this->assertSame('view', $controller->authorize( + $this->assertSame($response, $controller->authorize( m::mock(ServerRequestInterface::class), $request, $clients )); } @@ -221,16 +221,16 @@ public function test_authorization_view_is_presented_if_request_has_prompt_equal $clients->shouldReceive('find')->with(1)->andReturn($client = m::mock(Client::class)); $client->shouldReceive('skipsAuthorization')->andReturn(false); - $response->shouldReceive('withParameters')->once()->andReturnUsing(function ($data) use ($client, $user, $request) { + $response->shouldReceive('withParameters')->once()->andReturnUsing(function ($data) use ($client, $user, $request, $response) { $this->assertEquals($client, $data['client']); $this->assertEquals($user, $data['user']); $this->assertEquals($request, $data['request']); $this->assertSame('description', $data['scopes'][0]->description); - return 'view'; + return $response; }); - $this->assertSame('view', $controller->authorize( + $this->assertSame($response, $controller->authorize( m::mock(ServerRequestInterface::class), $request, $clients )); }