Skip to content

Commit 2cfa548

Browse files
committed
Add deprecation message for expiration verification
1 parent d2d6af0 commit 2cfa548

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/Token.php

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use function in_array;
2222
use function is_array;
2323
use function sprintf;
24+
use function trigger_error;
25+
use const E_USER_DEPRECATED;
2426

2527
/**
2628
* Basic structure of the JWT
@@ -303,6 +305,10 @@ public function isExpired(DateTimeInterface $now = null)
303305
return false;
304306
}
305307

308+
if ($now === null) {
309+
trigger_error('Not providing the current time is deprecated. Please pass an instance of DateTimeInterface.', E_USER_DEPRECATED);
310+
}
311+
306312
$now = $now ?: new DateTimeImmutable();
307313

308314
return $now > $this->claims->get(RegisteredClaims::EXPIRATION_TIME);

test/unit/TokenTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
*/
2828
class TokenTest extends \PHPUnit\Framework\TestCase
2929
{
30+
use CheckForDeprecations;
31+
3032
/**
3133
* @test
3234
*
@@ -920,6 +922,8 @@ public function isExpiredShouldReturnFalseWhenTokenDoesNotExpires()
920922
*/
921923
public function isExpiredShouldReturnFalseWhenTokenIsNotExpired()
922924
{
925+
$this->expectDeprecation('Not providing the current time is deprecated. Please pass an instance of DateTimeInterface.');
926+
923927
$token = new Token(
924928
['alg' => 'none'],
925929
['exp' => new DateTimeImmutable('+500 seconds')]

0 commit comments

Comments
 (0)