Skip to content

Commit 9af3bd9

Browse files
authored
Merge pull request #291 from jonkerw85/main
Fix PHPStan Issues
2 parents cd55a88 + ac0876b commit 9af3bd9

File tree

7 files changed

+26
-32
lines changed

7 files changed

+26
-32
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ You can find and compare releases at the [GitHub release page](https://github.co
99
## [Unreleased]
1010
### Fixed
1111
- Fixed the return type of getMinutesUntilExpired in BlackList, which returned a float instead of an int when using Carbon v2.
12+
- Fixed PHPStan issue in JWTGenerateSecretCommand by ensuring displayKey($key); is called before returning, avoiding returning a void method.
13+
- Fixed missing return true; statements in validatePayload() and validateRefresh() methods of Expiration.php, IssuedAt.php, and NotBefore.php to resolve PHPStan errors.
14+
- Fixed PHPStan error related to new static() by refactoring hasAllClaims method in Collection class.
15+
1216

1317
## [2.8.0] 2025-02-11
1418
Please see (https://github.com/PHP-Open-Source-Saver/jwt-auth/releases/tag/2.8.0)

phpstan-baseline.neon

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
5-
count: 1
6-
path: src/Claims/Collection.php
7-
8-
-
9-
message: "#^Method PHPOpenSourceSaver\\\\JWTAuth\\\\Claims\\\\Expiration\\:\\:validatePayload\\(\\) should return bool but return statement is missing\\.$#"
10-
count: 1
11-
path: src/Claims/Expiration.php
12-
13-
-
14-
message: "#^Method PHPOpenSourceSaver\\\\JWTAuth\\\\Claims\\\\IssuedAt\\:\\:validatePayload\\(\\) should return bool but return statement is missing\\.$#"
15-
count: 1
16-
path: src/Claims/IssuedAt.php
17-
18-
-
19-
message: "#^Method PHPOpenSourceSaver\\\\JWTAuth\\\\Claims\\\\IssuedAt\\:\\:validateRefresh\\(\\) should return bool but return statement is missing\\.$#"
20-
count: 1
21-
path: src/Claims/IssuedAt.php
22-
23-
-
24-
message: "#^Method PHPOpenSourceSaver\\\\JWTAuth\\\\Claims\\\\NotBefore\\:\\:validatePayload\\(\\) should return bool but return statement is missing\\.$#"
25-
count: 1
26-
path: src/Claims/NotBefore.php
27-
28-
-
29-
message: "#^Result of method PHPOpenSourceSaver\\\\JWTAuth\\\\Console\\\\JWTGenerateSecretCommand\\:\\:displayKey\\(\\) \\(void\\) is used\\.$#"
30-
count: 1
31-
path: src/Console/JWTGenerateSecretCommand.php
32-
333
-
344
message: "#^Class Laravel\\\\Octane\\\\Events\\\\RequestReceived not found\\.$#"
355
count: 1

src/Claims/Collection.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,17 @@ public function validate($context = 'payload')
7070
*/
7171
public function hasAllClaims($claims)
7272
{
73-
return count($claims) && (new static($claims))->diff($this->keys())->isEmpty();
73+
if (!count($claims)) {
74+
return false;
75+
}
76+
77+
foreach ($claims as $claim) {
78+
if (!$this->has($claim)) {
79+
return false;
80+
}
81+
}
82+
83+
return true;
7484
}
7585

7686
/**

src/Claims/Expiration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@ public function validatePayload()
2525
if ($this->isPast($this->getValue())) {
2626
throw new TokenExpiredException('Token has expired');
2727
}
28+
29+
return true;
2830
}
2931
}

src/Claims/IssuedAt.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,16 @@ public function validatePayload()
4040
if ($this->isFuture($this->getValue())) {
4141
throw new TokenInvalidException('Issued At (iat) timestamp cannot be in the future');
4242
}
43+
44+
return true;
4345
}
4446

4547
public function validateRefresh($refreshTTL)
4648
{
4749
if ($this->isPast($this->getValue() + $refreshTTL * 60)) {
4850
throw new TokenExpiredException('Token has expired and can no longer be refreshed');
4951
}
52+
53+
return true;
5054
}
5155
}

src/Claims/NotBefore.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ public function validatePayload()
2828
if ($this->isFuture($this->getValue())) {
2929
throw new TokenInvalidException('Not Before (nbf) timestamp cannot be in the future');
3030
}
31+
32+
return true;
3133
}
3234
}

src/Console/JWTGenerateSecretCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ public function handle()
5252
}
5353

5454
if (!$this->envFileExists()) {
55-
return $this->displayKey($key);
55+
$this->displayKey($key);
56+
57+
return;
5658
}
5759

5860
$updated = $this->updateEnvEntry('JWT_SECRET', $key, function () {

0 commit comments

Comments
 (0)