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

ExpirationTimeChecker::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
final class ExpirationTimeChecker implements ClaimCheckerInterface
17
{
18
    private const CLAIM_NAME = 'exp';
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function checkClaim($value)
24
    {
25
        if (!is_int($value)) {
26
            throw new \InvalidArgumentException('"exp" must be an integer.');
27
        }
28
        if (time() > $value) {
29
            throw new \InvalidArgumentException('The JWT has expired.');
30
        }
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function supportedClaim(): string
37
    {
38
        return self::CLAIM_NAME;
39
    }
40
}
41