Failed Conditions
Push — master ( 7c4f18...6ad094 )
by Florent
09:39
created

IssuedAtChecker   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A checkClaim() 0 9 3
A supportedClaim() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace Jose\Component\Checker;
15
16
/**
17
 * Class IssuedAtChecker.
18
 */
19
final class IssuedAtChecker implements ClaimChecker
20
{
21
    private const CLAIM_NAME = 'iat';
22
23
    /**
24
     * @var int
25
     */
26
    private $allowedTimeDrift;
27
28
    /**
29
     * ExpirationTimeChecker constructor.
30
     *
31
     * @param int $allowedTimeDrift
32
     */
33
    public function __construct(int $allowedTimeDrift = 0)
34
    {
35
        $this->allowedTimeDrift = $allowedTimeDrift;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function checkClaim($value)
42
    {
43
        if (!is_int($value)) {
44
            throw new InvalidClaimException('The claim "iat" must be an integer.', self::CLAIM_NAME, $value);
45
        }
46
        if (time() < $value - $this->allowedTimeDrift) {
47
            throw new InvalidClaimException('The JWT is issued in the future.', self::CLAIM_NAME, $value);
48
        }
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function supportedClaim(): string
55
    {
56
        return self::CLAIM_NAME;
57
    }
58
}
59