Failed Conditions
Push — master ( f0c028...ba72c1 )
by Florent
05:06
created

IssuedAtChecker::checkValue()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 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 ClaimCheckerInterface
20
{
21
    private const CLAIM_NAME = 'iat';
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function checkClaim($value)
27
    {
28
        if (!is_int($value)) {
29
            throw new \InvalidArgumentException('The claim "iat" must be an integer.');
30
        }
31
        if (time() < $value) {
32
            throw new \InvalidArgumentException('The JWT is issued in the future.');
33
        }
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function supportedClaim(): string
40
    {
41
        return self::CLAIM_NAME;
42
    }
43
}
44