Completed
Push — master ( 5fa11f...b77d4e )
by Tobias
05:30
created

Token::getRefreshToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This software may be modified and distributed under the terms
5
 * of the MIT license. See the LICENSE file for details.
6
 */
7
8
namespace Happyr\Auth0Bundle\Model\Authorization\Token;
9
10
use Happyr\Auth0Bundle\Model\ApiResponse;
11
12
/**
13
 * @author Tobias Nyholm <[email protected]>
14
 */
15
final class Token implements ApiResponse
16
{
17
    /**
18
     * @var string
19
     */
20
    private $accessToken;
21
22
    /**
23
     * @var string
24
     */
25
    private $refreshToken;
26
27
    /**
28
     * @var string
29
     */
30
    private $idToken;
31
32
    /**
33
     * @var string
34
     */
35
    private $tokenType;
36
37
    /**
38
     * @var int
39
     */
40
    private $expiresIn;
41
42
    /**
43
     * @var \DateTimeInterface
44
     */
45
    private $expiresAt;
46
47
    public function __construct(string $tokenType, int $expiresIn)
48
    {
49
        $this->tokenType = $tokenType;
50
        $this->expiresIn = $expiresIn;
51
        $this->expiresAt = (new \DateTimeImmutable())->modify('+'.$expiresIn.' seconds');
52
    }
53
54
    public static function create(array $data): Token
55
    {
56
        $token = new self($data['token_type'], (int) $data['expires_in']);
57
58
        if (isset($data['access_token'])) {
59
            $token->accessToken = $data['access_token'];
60
        }
61
        if (isset($data['refresh_token'])) {
62
            $token->refreshToken = $data['refresh_token'];
63
        }
64
        if (isset($data['id_token'])) {
65
            $token->idToken = $data['id_token'];
66
        }
67
68
        return $token;
69
    }
70
71
    public function getAccessToken(): ?string
72
    {
73
        return $this->accessToken;
74
    }
75
76
    public function getRefreshToken(): ?string
77
    {
78
        return $this->refreshToken;
79
    }
80
81
    public function getIdToken(): ?string
82
    {
83
        return $this->idToken;
84
    }
85
86
    public function getTokenType(): string
87
    {
88
        return $this->tokenType;
89
    }
90
91
    public function getExpiresIn(): int
92
    {
93
        return $this->expiresIn;
94
    }
95
96
    public function getExpiresAt(): \DateTimeInterface
97
    {
98
        return $this->expiresAt;
99
    }
100
}
101