Completed
Push — master ( 57aa9a...9d09aa )
by Jacob
02:21
created

ValidationData::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 11
cts 11
cp 1
rs 9.4285
cc 2
eloc 10
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016 Canis.io
4
 * @license   MIT
5
 * @license   http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
6
 */
7
namespace Canis\Lumen\Jwt\Adapters\Lcobucci;
8
9
/**
10
 * Class that wraps validation values
11
 * Jacob added the ability to override just the expiration validator
12
 *
13
 * @author Luís Otávio Cobucci Oblonczyk <[email protected]>
14
 * @author Jacob Morrison <[email protected]>
15
 */
16
class ValidationData 
17
    extends \Lcobucci\JWT\ValidationData
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
18
{
19
    /**
20
     * The list of things to be validated
21
     *
22
     * @var array
23
     */
24
    private $items;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
25
26
    /**
27
     * Initializes the object
28
     *
29
     * @param int $currentTime
30
     */
31 25
    public function __construct($currentTime = null)
32
    {
33 25
        $currentTime = $currentTime ?: time();
34
35 25
        $this->items = [
36 25
            'jti' => null,
37 25
            'iss' => null,
38 25
            'aud' => null,
39 25
            'sub' => null,
40 25
            'iat' => $currentTime,
41 25
            'nbf' => $currentTime,
42
            'exp' => $currentTime
43 25
        ];
44 25
    }
45
46
    /**
47
     * Configures the id
48
     *
49
     * @param string $id
50
     */
51 1
    public function setId($id)
52
    {
53 1
        $this->items['jti'] = (string) $id;
54 1
    }
55
56
    /**
57
     * Configures the issuer
58
     *
59
     * @param string $issuer
60
     */
61 18
    public function setIssuer($issuer)
62
    {
63 18
        $this->items['iss'] = (string) $issuer;
64 18
    }
65
66
    /**
67
     * Configures the audience
68
     *
69
     * @param string $audience
70
     */
71 2
    public function setAudience($audience)
72
    {
73 2
        $this->items['aud'] = (string) $audience;
74 2
    }
75
76
    /**
77
     * Configures the subject
78
     *
79
     * @param string $subject
80
     */
81 1
    public function setSubject($subject)
82
    {
83 1
        $this->items['sub'] = (string) $subject;
84 1
    }
85
86
    /**
87
     * Configures the time that "iat", "nbf" and "exp" should be based on
88
     *
89
     * @param int $currentTime
90
     */
91 1
    public function setCurrentTime($currentTime)
92
    {
93 1
        $this->items['iat'] = (int) $currentTime;
94 1
        $this->items['nbf'] = (int) $currentTime;
95 1
        $this->items['exp'] = (int) $currentTime;
96 1
    }
97
98
    /**
99
     * Configures the time that "exp" should be based on
100
     *
101
     * @param int $currentTime
102
     */
103 8
    public function setExpiration($currentTime)
104
    {
105 8
        $this->items['exp'] = (int) $currentTime;
106 8
    }
107
108
    /**
109
     * Returns the requested item
110
     *
111
     * @param string $name
112
     *
113
     * @return mixed
114
     */
115 24
    public function get($name)
116
    {
117 24
        return isset($this->items[$name]) ? $this->items[$name] : null;
118
    }
119
120
    /**
121
     * Returns if the item is present
122
     *
123
     * @param string $name
124
     *
125
     * @return boolean
126
     */
127 18
    public function has($name)
128
    {
129 18
        return !empty($this->items[$name]);
130
    }
131
}