Passed
Pull Request — master (#101)
by Łukasz
03:05
created

Token   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isNonExpired() 0 3 1
A __construct() 0 6 1
A getToken() 0 3 1
1
<?php
2
3
/**
4
 * (c) FSi sp. z o.o. <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace FSi\Bundle\AdminSecurityBundle\Security\Token;
11
12
use DateInterval;
13
use DateTime;
14
15
class Token implements TokenInterface
16
{
17
    /**
18
     * @var string
19
     */
20
    protected $token;
21
22
    /**
23
     * @var DateTime
24
     */
25
    protected $createdAt;
26
27
    /**
28
     * @var DateTime
29
     */
30
    protected $expiresAt;
31
32
    /**
33
     * @param $token
34
     * @param DateTime $createdAt
35
     * @param DateInterval $ttl
36
     */
37
    public function __construct($token, DateTime $createdAt, DateInterval $ttl)
38
    {
39
        $this->token = $token;
40
        $this->createdAt = clone $createdAt;
41
        $this->expiresAt = clone $this->createdAt;
42
        $this->expiresAt->add($ttl);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function getToken()
49
    {
50
        return $this->token;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function isNonExpired()
57
    {
58
        return new DateTime() <= $this->expiresAt;
59
    }
60
}
61