Completed
Push — master ( e214c2...9b8774 )
by Kevin
02:27
created

ExpiresAtValidator::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 2
eloc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Zenstruck\JWT\Validator;
4
5
use Zenstruck\JWT\Exception\Validation\ExpiredToken;
6
use Zenstruck\JWT\Exception\Validation\MissingClaim;
7
use Zenstruck\JWT\Token;
8
use Zenstruck\JWT\Validator;
9
10
/**
11
 * @author Kevin Bond <[email protected]>
12
 */
13 View Code Duplication
final class ExpiresAtValidator implements Validator
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    private $currentTime;
16
17
    /**
18
     * @param \DateTime|null $currentTime
19
     */
20 9
    public function __construct(\DateTime $currentTime = null)
21
    {
22 9
        $this->currentTime = $currentTime ?: new \DateTime('now');
23 9
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 5
    public function validate(Token $token)
29
    {
30 5
        if (null === $token->expiresAt()) {
31 1
            throw new MissingClaim(Token::CLAIM_EXP, $token);
32
        }
33
34 4
        if ($token->isExpired($this->currentTime)) {
35 2
            throw new ExpiredToken($token);
36
        }
37 2
    }
38
}
39