Failed Conditions
Pull Request — master (#308)
by Gareth
04:37
created

NotBeforeChecker   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A checkClaim() 0 11 2
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2017 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 Assert\Assertion;
15
use Jose\Object\JWTInterface;
16
17
class NotBeforeChecker implements ClaimCheckerInterface
18
{
19
    private $tolerance;
20
21
    public function __construct($tolerance = 0)
22
    {
23
        Assertion::greaterOrEqualThan($tolerance, 0, 'Tolerance value must be >=0');
24
        $this->tolerance = (int) $tolerance;
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function checkClaim(JWTInterface $jwt)
31
    {
32
        if (!$jwt->hasClaim('nbf')) {
33
            return [];
34
        }
35
36
        $nbf = (int) $jwt->getClaim('nbf') - $this->tolerance;
37
        Assertion::lessOrEqualThan($nbf, time(), 'The JWT can not be used yet.');
38
39
        return ['nbf'];
40
    }
41
}
42