Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/Auth/GatewayGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(
*
* @return mixed|null
*/
public function user()
public function user(): ?AuthenticatableContract
{
if ($this->loggedOut) {
return null;
Expand Down Expand Up @@ -139,7 +139,7 @@ protected function retrieveUserData(): ?array
* @param string $token
* @return void
*/
protected function updateSession($token)
protected function updateSession($token): void
{
$this->session->put($this->getName(), $token);
// $this->session->migrate(true); Conflicts with CSRF
Expand All @@ -163,7 +163,7 @@ public function token(): ?string
* @param bool $remember
* @return bool
*/
public function attempt(array $credentials = [], $remember = false)
public function attempt(array $credentials = [], $remember = false): bool
{
$response = $this->client->login($credentials);
$token = $response['access_token'] ?? null;
Expand All @@ -190,7 +190,7 @@ public function attempt(array $credentials = [], $remember = false)
*
* @param bool $remember
*/
public function loginWithToken(string $token, array $userData = [], $remember = false): void
public function loginWithToken(string $token, array $userData = [], bool $remember = false): void
{
$this->token = $token;
$this->updateSession($token);
Expand All @@ -216,7 +216,7 @@ public function loginWithToken(string $token, array $userData = [], $remember =
* @param bool $remember
* @return void
*/
public function login(AuthenticatableContract $user, $remember = false)
public function login(AuthenticatableContract $user, $remember = false): void
{
$this->setUser($user);
$this->fireLoginEvent($user, $remember);
Expand All @@ -227,7 +227,7 @@ public function login(AuthenticatableContract $user, $remember = false)
*
* @return void
*/
public function logout()
public function logout(): void
{
$this->clearUserDataFromStorage();
$this->token = null;
Expand All @@ -240,7 +240,7 @@ public function logout()
*
* @return bool
*/
public function viaRemember()
public function viaRemember(): bool
{
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Console/ModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#[AsCommand(name: 'make:model', description: 'Create a new Eloquent model class')]
class ModelMakeCommand extends BaseModelMakeCommand
{
protected function getOptions()
protected function getOptions(): array
{
return array_merge(parent::getOptions(), [
['remote', null, InputOption::VALUE_NONE, 'Indicates the model should extend the package base model'],
]);
}

protected function getStub()
protected function getStub(): string
{
if ($this->option('remote')) {
return __DIR__.'/stubs/remote-model.stub';
Expand Down
8 changes: 4 additions & 4 deletions src/Contracts/ApiGatewayClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

interface ApiGatewayClientInterface
{
public function get(string $uri, array $query = []);
public function get(string $uri, array $query = []): mixed;

public function post(string $uri, array $data = []);
public function post(string $uri, array $data = []): mixed;

public function put(string $uri, array $data = []);
public function put(string $uri, array $data = []): mixed;

public function delete(string $uri);
public function delete(string $uri): mixed;
}
10 changes: 5 additions & 5 deletions src/Services/ApiGatewayClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,35 @@ public static function directWithToken(string $token): static
return new static(Http::apiGatewayDirectWithToken($token));
}

public function get(string $uri, array $query = [])
public function get(string $uri, array $query = []): mixed
{
return $this->handleResponse(
$this->http->get($uri, $query)
);
}

public function post(string $uri, array $data = [])
public function post(string $uri, array $data = []): mixed
{
return $this->handleResponse(
$this->http->post($uri, $data)
);
}

public function put(string $uri, array $data = [])
public function put(string $uri, array $data = []): mixed
{
return $this->handleResponse(
$this->http->put($uri, $data)
);
}

public function delete(string $uri)
public function delete(string $uri): mixed
{
return $this->handleResponse(
$this->http->delete($uri)
);
}

protected function handleResponse($response)
protected function handleResponse(mixed $response): mixed
{
if (is_object($response) && method_exists($response, 'failed') && $response->failed()) {
$data = method_exists($response, 'json') ? $response->json() : [];
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/RedirectsIfRequested.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

trait RedirectsIfRequested
{
protected function redirectIfRequested(Request $request, $response)
protected function redirectIfRequested(Request $request, mixed $response): mixed
{
if ($request->has('redirect')) {
$redirectTo = $request->input('redirect');
Expand Down
30 changes: 15 additions & 15 deletions tests/Models/ApiModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function all_users_gateway()
{
// Simulate the gateway returning an array of users
$this->gateway = new class () extends FakeGatewayClient {
public function get(string $uri, array $query = [])
public function get(string $uri, array $query = []): mixed
{
parent::get($uri, $query);

Expand All @@ -90,7 +90,7 @@ public function get(string $uri, array $query = [])
public function find_users_gateway()
{
$this->gateway = new class () extends FakeGatewayClient {
public function get(string $uri, array $query = [])
public function get(string $uri, array $query = []): mixed
{
parent::get($uri, $query);
if ($uri === '/users/5') {
Expand All @@ -113,7 +113,7 @@ public function get(string $uri, array $query = [])
public function find_users_gateway_returns_null_when_not_found()
{
$this->gateway = new class () extends FakeGatewayClient {
public function get(string $uri, array $query = [])
public function get(string $uri, array $query = []): mixed
{
parent::get($uri, $query);

Expand All @@ -131,7 +131,7 @@ public function get(string $uri, array $query = [])
public function create_users_gateway()
{
$this->gateway = new class () extends FakeGatewayClient {
public function post(string $uri, array $data = [])
public function post(string $uri, array $data = []): mixed
{
parent::post($uri, $data);

Expand All @@ -152,7 +152,7 @@ public function post(string $uri, array $data = [])
public function all_users_gateway_handles_empty_response()
{
$this->gateway = new class () extends FakeGatewayClient {
public function get(string $uri, array $query = [])
public function get(string $uri, array $query = []): mixed
{
parent::get($uri, $query);

Expand All @@ -171,7 +171,7 @@ public function get(string $uri, array $query = [])
public function all_users_gateway_handles_api_failure()
{
$this->gateway = new class () extends FakeGatewayClient {
public function get(string $uri, array $query = [])
public function get(string $uri, array $query = []): mixed
{
parent::get($uri, $query);

Expand Down Expand Up @@ -242,7 +242,7 @@ public function delete_users_respects_configured_method()
public function delete_returns_false_on_failed_response()
{
$this->gateway = new class () extends FakeGatewayClient {
public function delete(string $uri)
public function delete(string $uri): mixed
{
parent::delete($uri);

Expand All @@ -266,7 +266,7 @@ public function successful()
public function static_update_users_gateway()
{
$this->gateway = new class () extends FakeGatewayClient {
public function put(string $uri, array $data = [])
public function put(string $uri, array $data = []): mixed
{
parent::put($uri, $data);

Expand All @@ -286,7 +286,7 @@ public function put(string $uri, array $data = [])
public function static_update_returns_false_on_failed_response()
{
$this->gateway = new class () extends FakeGatewayClient {
public function put(string $uri, array $data = [])
public function put(string $uri, array $data = []): mixed
{
parent::put($uri, $data);

Expand Down Expand Up @@ -327,7 +327,7 @@ public function instance_update_users_gateway()
public function update_returns_false_on_failed_response()
{
$this->gateway = new class () extends FakeGatewayClient {
public function put(string $uri, array $data = [])
public function put(string $uri, array $data = []): mixed
{
parent::put($uri, $data);

Expand Down Expand Up @@ -356,7 +356,7 @@ public function json()
public function update_propagates_api_gateway_exceptions()
{
$this->gateway = new class () extends FakeGatewayClient {
public function put(string $uri, array $data = [])
public function put(string $uri, array $data = []): mixed
{
parent::put($uri, $data);

Expand All @@ -377,7 +377,7 @@ public function put(string $uri, array $data = [])
public function find_or_fail_throws_when_not_found()
{
$this->gateway = new class () extends FakeGatewayClient {
public function get(string $uri, array $query = [])
public function get(string $uri, array $query = []): mixed
{
parent::get($uri, $query);

Expand All @@ -395,7 +395,7 @@ public function get(string $uri, array $query = [])
public function update_or_fail_throws_on_failure()
{
$this->gateway = new class () extends FakeGatewayClient {
public function put(string $uri, array $data = [])
public function put(string $uri, array $data = []): mixed
{
parent::put($uri, $data);

Expand All @@ -421,7 +421,7 @@ public function successful()
public function where_get_filters_results()
{
$this->gateway = new class () extends FakeGatewayClient {
public function get(string $uri, array $query = [])
public function get(string $uri, array $query = []): mixed
{
parent::get($uri, $query);

Expand Down Expand Up @@ -493,7 +493,7 @@ public function from_api_response_maps_nested_relations()
public function paginate_returns_empty_paginator_on_404()
{
$this->gateway = new class () extends FakeGatewayClient {
public function get(string $uri, array $query = [])
public function get(string $uri, array $query = []): mixed
{
parent::get($uri, $query);

Expand Down
6 changes: 3 additions & 3 deletions tests/Rules/ExistsRemoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function setUp(): void
public function passes_when_all_ids_exist()
{
$this->gateway = new class () extends FakeGatewayClient {
public function get(string $uri, array $query = [])
public function get(string $uri, array $query = []): mixed
{
parent::get($uri, $query);
if (in_array($uri, ['/roles/1', '/roles/2'])) {
Expand All @@ -63,7 +63,7 @@ public function get(string $uri, array $query = [])
public function rule_object_works_the_same()
{
$this->gateway = new class () extends FakeGatewayClient {
public function get(string $uri, array $query = [])
public function get(string $uri, array $query = []): mixed
{
parent::get($uri, $query);
return ['data' => ['id' => (int) substr($uri, 7)]];
Expand All @@ -82,7 +82,7 @@ public function get(string $uri, array $query = [])
public function fails_when_any_id_is_missing()
{
$this->gateway = new class () extends FakeGatewayClient {
public function get(string $uri, array $query = [])
public function get(string $uri, array $query = []): mixed
{
parent::get($uri, $query);
if ($uri === '/roles/1') {
Expand Down
8 changes: 4 additions & 4 deletions tests/Services/FakeGatewayClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ class FakeGatewayClient implements ApiGatewayClientInterface
{
protected array $calls = [];

public function get(string $uri, array $query = [])
public function get(string $uri, array $query = []): mixed
{
$this->calls[] = ['method' => 'GET', 'uri' => $uri, 'query' => $query];

return collect(['fake' => true, 'uri' => $uri, 'query' => $query]);
}

public function post(string $uri, array $data = [])
public function post(string $uri, array $data = []): mixed
{
$this->calls[] = ['method' => 'POST', 'uri' => $uri, 'data' => $data];

return collect(['fake' => true, 'uri' => $uri, 'data' => $data]);
}

public function put(string $uri, array $data = [])
public function put(string $uri, array $data = []): mixed
{
$this->calls[] = ['method' => 'PUT', 'uri' => $uri, 'data' => $data];

return collect(['fake' => true, 'uri' => $uri, 'data' => $data]);
}

public function delete(string $uri)
public function delete(string $uri): mixed
{
$this->calls[] = ['method' => 'DELETE', 'uri' => $uri];

Expand Down
2 changes: 1 addition & 1 deletion tests/Services/PermissionsClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function setUp(): void
{
parent::setUp();
$this->gateway = new class () extends FakeGatewayClient {
public function get(string $uri, array $query = [])
public function get(string $uri, array $query = []): mixed
{
parent::get($uri, $query);

Expand Down