Skip to content

Commit 9612958

Browse files
authored
Merge pull request #6 from KroderDev/codex/review-methods-without-types-and-run-laravel-pint
Add type hints to gateway utilities
2 parents 80198b7 + 6b24dd3 commit 9612958

File tree

9 files changed

+42
-42
lines changed

9 files changed

+42
-42
lines changed

src/Auth/GatewayGuard.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct(
4545
*
4646
* @return mixed|null
4747
*/
48-
public function user()
48+
public function user(): ?AuthenticatableContract
4949
{
5050
if ($this->loggedOut) {
5151
return null;
@@ -139,7 +139,7 @@ protected function retrieveUserData(): ?array
139139
* @param string $token
140140
* @return void
141141
*/
142-
protected function updateSession($token)
142+
protected function updateSession($token): void
143143
{
144144
$this->session->put($this->getName(), $token);
145145
// $this->session->migrate(true); Conflicts with CSRF
@@ -163,7 +163,7 @@ public function token(): ?string
163163
* @param bool $remember
164164
* @return bool
165165
*/
166-
public function attempt(array $credentials = [], $remember = false)
166+
public function attempt(array $credentials = [], $remember = false): bool
167167
{
168168
$response = $this->client->login($credentials);
169169
$token = $response['access_token'] ?? null;
@@ -190,7 +190,7 @@ public function attempt(array $credentials = [], $remember = false)
190190
*
191191
* @param bool $remember
192192
*/
193-
public function loginWithToken(string $token, array $userData = [], $remember = false): void
193+
public function loginWithToken(string $token, array $userData = [], bool $remember = false): void
194194
{
195195
$this->token = $token;
196196
$this->updateSession($token);
@@ -216,7 +216,7 @@ public function loginWithToken(string $token, array $userData = [], $remember =
216216
* @param bool $remember
217217
* @return void
218218
*/
219-
public function login(AuthenticatableContract $user, $remember = false)
219+
public function login(AuthenticatableContract $user, $remember = false): void
220220
{
221221
$this->setUser($user);
222222
$this->fireLoginEvent($user, $remember);
@@ -227,7 +227,7 @@ public function login(AuthenticatableContract $user, $remember = false)
227227
*
228228
* @return void
229229
*/
230-
public function logout()
230+
public function logout(): void
231231
{
232232
$this->clearUserDataFromStorage();
233233
$this->token = null;
@@ -240,7 +240,7 @@ public function logout()
240240
*
241241
* @return bool
242242
*/
243-
public function viaRemember()
243+
public function viaRemember(): bool
244244
{
245245
return false;
246246
}

src/Console/ModelMakeCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
#[AsCommand(name: 'make:model', description: 'Create a new Eloquent model class')]
1010
class ModelMakeCommand extends BaseModelMakeCommand
1111
{
12-
protected function getOptions()
12+
protected function getOptions(): array
1313
{
1414
return array_merge(parent::getOptions(), [
1515
['remote', null, InputOption::VALUE_NONE, 'Indicates the model should extend the package base model'],
1616
]);
1717
}
1818

19-
protected function getStub()
19+
protected function getStub(): string
2020
{
2121
if ($this->option('remote')) {
2222
return __DIR__.'/stubs/remote-model.stub';

src/Contracts/ApiGatewayClientInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
interface ApiGatewayClientInterface
66
{
7-
public function get(string $uri, array $query = []);
7+
public function get(string $uri, array $query = []): mixed;
88

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

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

13-
public function delete(string $uri);
13+
public function delete(string $uri): mixed;
1414
}

src/Services/ApiGatewayClient.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,35 @@ public static function directWithToken(string $token): static
3636
return new static(Http::apiGatewayDirectWithToken($token));
3737
}
3838

39-
public function get(string $uri, array $query = [])
39+
public function get(string $uri, array $query = []): mixed
4040
{
4141
return $this->handleResponse(
4242
$this->http->get($uri, $query)
4343
);
4444
}
4545

46-
public function post(string $uri, array $data = [])
46+
public function post(string $uri, array $data = []): mixed
4747
{
4848
return $this->handleResponse(
4949
$this->http->post($uri, $data)
5050
);
5151
}
5252

53-
public function put(string $uri, array $data = [])
53+
public function put(string $uri, array $data = []): mixed
5454
{
5555
return $this->handleResponse(
5656
$this->http->put($uri, $data)
5757
);
5858
}
5959

60-
public function delete(string $uri)
60+
public function delete(string $uri): mixed
6161
{
6262
return $this->handleResponse(
6363
$this->http->delete($uri)
6464
);
6565
}
6666

67-
protected function handleResponse($response)
67+
protected function handleResponse(mixed $response): mixed
6868
{
6969
if (is_object($response) && method_exists($response, 'failed') && $response->failed()) {
7070
$data = method_exists($response, 'json') ? $response->json() : [];

src/Traits/RedirectsIfRequested.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
trait RedirectsIfRequested
1111
{
12-
protected function redirectIfRequested(Request $request, $response)
12+
protected function redirectIfRequested(Request $request, mixed $response): mixed
1313
{
1414
if ($request->has('redirect')) {
1515
$redirectTo = $request->input('redirect');

tests/Models/ApiModelTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function all_users_gateway()
6666
{
6767
// Simulate the gateway returning an array of users
6868
$this->gateway = new class () extends FakeGatewayClient {
69-
public function get(string $uri, array $query = [])
69+
public function get(string $uri, array $query = []): mixed
7070
{
7171
parent::get($uri, $query);
7272

@@ -90,7 +90,7 @@ public function get(string $uri, array $query = [])
9090
public function find_users_gateway()
9191
{
9292
$this->gateway = new class () extends FakeGatewayClient {
93-
public function get(string $uri, array $query = [])
93+
public function get(string $uri, array $query = []): mixed
9494
{
9595
parent::get($uri, $query);
9696
if ($uri === '/users/5') {
@@ -113,7 +113,7 @@ public function get(string $uri, array $query = [])
113113
public function find_users_gateway_returns_null_when_not_found()
114114
{
115115
$this->gateway = new class () extends FakeGatewayClient {
116-
public function get(string $uri, array $query = [])
116+
public function get(string $uri, array $query = []): mixed
117117
{
118118
parent::get($uri, $query);
119119

@@ -131,7 +131,7 @@ public function get(string $uri, array $query = [])
131131
public function create_users_gateway()
132132
{
133133
$this->gateway = new class () extends FakeGatewayClient {
134-
public function post(string $uri, array $data = [])
134+
public function post(string $uri, array $data = []): mixed
135135
{
136136
parent::post($uri, $data);
137137

@@ -152,7 +152,7 @@ public function post(string $uri, array $data = [])
152152
public function all_users_gateway_handles_empty_response()
153153
{
154154
$this->gateway = new class () extends FakeGatewayClient {
155-
public function get(string $uri, array $query = [])
155+
public function get(string $uri, array $query = []): mixed
156156
{
157157
parent::get($uri, $query);
158158

@@ -171,7 +171,7 @@ public function get(string $uri, array $query = [])
171171
public function all_users_gateway_handles_api_failure()
172172
{
173173
$this->gateway = new class () extends FakeGatewayClient {
174-
public function get(string $uri, array $query = [])
174+
public function get(string $uri, array $query = []): mixed
175175
{
176176
parent::get($uri, $query);
177177

@@ -242,7 +242,7 @@ public function delete_users_respects_configured_method()
242242
public function delete_returns_false_on_failed_response()
243243
{
244244
$this->gateway = new class () extends FakeGatewayClient {
245-
public function delete(string $uri)
245+
public function delete(string $uri): mixed
246246
{
247247
parent::delete($uri);
248248

@@ -266,7 +266,7 @@ public function successful()
266266
public function static_update_users_gateway()
267267
{
268268
$this->gateway = new class () extends FakeGatewayClient {
269-
public function put(string $uri, array $data = [])
269+
public function put(string $uri, array $data = []): mixed
270270
{
271271
parent::put($uri, $data);
272272

@@ -286,7 +286,7 @@ public function put(string $uri, array $data = [])
286286
public function static_update_returns_false_on_failed_response()
287287
{
288288
$this->gateway = new class () extends FakeGatewayClient {
289-
public function put(string $uri, array $data = [])
289+
public function put(string $uri, array $data = []): mixed
290290
{
291291
parent::put($uri, $data);
292292

@@ -327,7 +327,7 @@ public function instance_update_users_gateway()
327327
public function update_returns_false_on_failed_response()
328328
{
329329
$this->gateway = new class () extends FakeGatewayClient {
330-
public function put(string $uri, array $data = [])
330+
public function put(string $uri, array $data = []): mixed
331331
{
332332
parent::put($uri, $data);
333333

@@ -356,7 +356,7 @@ public function json()
356356
public function update_propagates_api_gateway_exceptions()
357357
{
358358
$this->gateway = new class () extends FakeGatewayClient {
359-
public function put(string $uri, array $data = [])
359+
public function put(string $uri, array $data = []): mixed
360360
{
361361
parent::put($uri, $data);
362362

@@ -377,7 +377,7 @@ public function put(string $uri, array $data = [])
377377
public function find_or_fail_throws_when_not_found()
378378
{
379379
$this->gateway = new class () extends FakeGatewayClient {
380-
public function get(string $uri, array $query = [])
380+
public function get(string $uri, array $query = []): mixed
381381
{
382382
parent::get($uri, $query);
383383

@@ -395,7 +395,7 @@ public function get(string $uri, array $query = [])
395395
public function update_or_fail_throws_on_failure()
396396
{
397397
$this->gateway = new class () extends FakeGatewayClient {
398-
public function put(string $uri, array $data = [])
398+
public function put(string $uri, array $data = []): mixed
399399
{
400400
parent::put($uri, $data);
401401

@@ -421,7 +421,7 @@ public function successful()
421421
public function where_get_filters_results()
422422
{
423423
$this->gateway = new class () extends FakeGatewayClient {
424-
public function get(string $uri, array $query = [])
424+
public function get(string $uri, array $query = []): mixed
425425
{
426426
parent::get($uri, $query);
427427

@@ -493,7 +493,7 @@ public function from_api_response_maps_nested_relations()
493493
public function paginate_returns_empty_paginator_on_404()
494494
{
495495
$this->gateway = new class () extends FakeGatewayClient {
496-
public function get(string $uri, array $query = [])
496+
public function get(string $uri, array $query = []): mixed
497497
{
498498
parent::get($uri, $query);
499499

tests/Rules/ExistsRemoteTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected function setUp(): void
3838
public function passes_when_all_ids_exist()
3939
{
4040
$this->gateway = new class () extends FakeGatewayClient {
41-
public function get(string $uri, array $query = [])
41+
public function get(string $uri, array $query = []): mixed
4242
{
4343
parent::get($uri, $query);
4444
if (in_array($uri, ['/roles/1', '/roles/2'])) {
@@ -63,7 +63,7 @@ public function get(string $uri, array $query = [])
6363
public function rule_object_works_the_same()
6464
{
6565
$this->gateway = new class () extends FakeGatewayClient {
66-
public function get(string $uri, array $query = [])
66+
public function get(string $uri, array $query = []): mixed
6767
{
6868
parent::get($uri, $query);
6969
return ['data' => ['id' => (int) substr($uri, 7)]];
@@ -82,7 +82,7 @@ public function get(string $uri, array $query = [])
8282
public function fails_when_any_id_is_missing()
8383
{
8484
$this->gateway = new class () extends FakeGatewayClient {
85-
public function get(string $uri, array $query = [])
85+
public function get(string $uri, array $query = []): mixed
8686
{
8787
parent::get($uri, $query);
8888
if ($uri === '/roles/1') {

tests/Services/FakeGatewayClient.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ class FakeGatewayClient implements ApiGatewayClientInterface
88
{
99
protected array $calls = [];
1010

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

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

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

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

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

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

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

tests/Services/PermissionsClientTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected function setUp(): void
2727
{
2828
parent::setUp();
2929
$this->gateway = new class () extends FakeGatewayClient {
30-
public function get(string $uri, array $query = [])
30+
public function get(string $uri, array $query = []): mixed
3131
{
3232
parent::get($uri, $query);
3333

0 commit comments

Comments
 (0)