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

ExpirationTimeChecker   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
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
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