Completed
Push — master ( 0f6cd0...ce5be5 )
by Florent
41:39 queued 33s
created

IssuedAtChecker::checkClaim()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 13
rs 9.4285
cc 3
eloc 7
nc 3
nop 1
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace Jose\Checker;
13
14
use Jose\Object\JWTInterface;
15
16
class IssuedAtChecker implements ClaimCheckerInterface
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function checkClaim(JWTInterface $jwt)
22
    {
23
        if (!$jwt->hasClaim('iat')) {
24
            return [];
25
        }
26
27
        $iat = (int) $jwt->getClaim('iat');
28
        if (time() < $iat) {
29
            throw new \Exception('The JWT is issued in the futur.');
30
        }
31
32
        return ['iat'];
33
    }
34
}
35