Completed
Push — master ( 2b3071...0563c6 )
by Yann
02:03
created

Token::getPayload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Yokai\SecurityTokenBundle\Entity;
4
5
use DateTime;
6
7
/**
8
 * @author Yann Eugoné <[email protected]>
9
 */
10
class Token
11
{
12
    /**
13
     * @var int
14
     */
15
    private $id;
16
17
    /**
18
     * @var string
19
     */
20
    private $userClass;
21
22
    /**
23
     * @var string
24
     */
25
    private $userId;
26
27
    /**
28
     * @var string
29
     */
30
    private $value;
31
32
    /**
33
     * @var string
34
     */
35
    private $purpose;
36
37
    /**
38
     * @var array
39
     */
40
    private $payload = [];
41
42
    /**
43
     * @var DateTime
44
     */
45
    private $createdAt;
46
47
    /**
48
     * @var array
49
     */
50
    private $createdInformation = [];
51
52
    /**
53
     * @var DateTime
54
     */
55
    private $expiresAt;
56
57
    /**
58
     * @var DateTime|null
59
     */
60
    private $usedAt;
61
62
    /**
63
     * @var array
64
     */
65
    private $usedInformation;
66
67
    /**
68
     * @param string $userClass
69
     * @param string $userId
70
     * @param string $value
71
     * @param string $purpose
72
     * @param string $duration
73
     * @param array  $payload
74
     * @param array  $information
75
     */
76 9
    public function __construct(
77
        $userClass,
78
        $userId,
79
        $value,
80
        $purpose,
81
        $duration,
82
        array $payload = [],
83
        array $information = []
84
    ) {
85 9
        $this->userClass = $userClass;
86 9
        $this->userId = $userId;
87 9
        $this->value = $value;
88 9
        $this->purpose = $purpose;
89 9
        $this->createdAt = new DateTime();
90 9
        $this->expiresAt = (new DateTime())->modify($duration);
91 9
        $this->payload = $payload;
92 9
        $this->createdInformation = $information;
93 9
    }
94
95
    /**
96
     * @return int
97
     */
98
    public function getId()
99
    {
100
        return $this->id;
101
    }
102
103
    /**
104
     * @return string
105
     */
106 2
    public function getUserClass()
107
    {
108 2
        return $this->userClass;
109
    }
110
111
    /**
112
     * @return string
113
     */
114 2
    public function getUserId()
115
    {
116 2
        return $this->userId;
117
    }
118
119
    /**
120
     * @return string
121
     */
122 2
    public function getValue()
123
    {
124 2
        return $this->value;
125
    }
126
127
    /**
128
     * @return string
129
     */
130 1
    public function getPurpose()
131
    {
132 1
        return $this->purpose;
133
    }
134
135
    /**
136
     * @return array
137
     */
138 1
    public function getPayload()
139
    {
140 1
        return $this->payload;
141
    }
142
143
    /**
144
     * @return DateTime
145
     */
146 1
    public function getCreatedAt()
147
    {
148 1
        return $this->createdAt;
149
    }
150
151
    /**
152
     * @return array
153
     */
154 1
    public function getCreatedInformation()
155
    {
156 1
        return $this->createdInformation;
157
    }
158
159
    /**
160
     * @return DateTime
161
     */
162 2
    public function getExpiresAt()
163
    {
164 2
        return $this->expiresAt;
165
    }
166
167
    /**
168
     * @return DateTime|null
169
     */
170 3
    public function getUsedAt()
171
    {
172 3
        return $this->usedAt;
173
    }
174
175
    /**
176
     * @param DateTime $usedAt
177
     */
178 2
    public function setUsedAt($usedAt)
179
    {
180 2
        $this->usedAt = $usedAt;
181 2
    }
182
183
    /**
184
     * @return array
185
     */
186 2
    public function getUsedInformation()
187
    {
188 2
        return $this->usedInformation;
189
    }
190
191
    /**
192
     * @param array $usedInformation
193
     */
194 2
    public function setUsedInformation($usedInformation)
195
    {
196 2
        $this->usedInformation = $usedInformation;
197 2
    }
198
199
    /**
200
     * @return boolean
201
     */
202 3
    public function isExpired()
203
    {
204 3
        return $this->expiresAt < new DateTime();
205
    }
206
207
    /**
208
     * @return boolean
209
     */
210 2
    public function isUsed()
211
    {
212 2
        return null !== $this->usedAt;
213
    }
214
}
215