Token::getToken()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
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
declare(strict_types=1);
11
12
namespace FSi\Bundle\AdminSecurityBundle\Security\Token;
13
14
use DateInterval;
15
use DateTime;
16
17
class Token implements TokenInterface
18
{
19
    /**
20
     * @var string
21
     */
22
    protected $token;
23
24
    /**
25
     * @var DateTime
26
     */
27
    protected $createdAt;
28
29
    /**
30
     * @var DateTime
31
     */
32
    protected $expiresAt;
33
34
    public function __construct(string $token, DateTime $createdAt, DateInterval $ttl)
35
    {
36
        $this->token = $token;
37
        $this->createdAt = clone $createdAt;
38
        $this->expiresAt = clone $this->createdAt;
39
        $this->expiresAt->add($ttl);
40
    }
41
42
    public function getToken(): string
43
    {
44
        return $this->token;
45
    }
46
47
    public function getExpiresAt(): DateTime
48
    {
49
        return $this->expiresAt;
50
    }
51
52
    public function isNonExpired(): bool
53
    {
54
        return new DateTime() <= $this->expiresAt;
55
    }
56
}
57