AccessToken   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 190
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 1
dl 0
loc 190
rs 10
c 0
b 0
f 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __toString() 0 4 1
A getId() 0 4 1
A getAccessToken() 0 4 1
A getRefreshToken() 0 4 1
A getExpireAt() 0 4 1
A isValid() 0 4 1
A getRefreshTokenExpireAt() 0 4 1
A getScope() 0 4 1
A setAccessToken() 0 6 1
A setRefreshToken() 0 6 1
A setExpireAt() 0 6 1
A setRefreshTokenExpireAt() 0 6 1
A setScope() 0 6 1
A hasScope() 0 6 1
A getSDKAccessToken() 0 10 1
1
<?php
2
3
namespace Mailxpert\APIBundle\Model;
4
5
use Mailxpert\Authentication\AccessToken as SDKAccessToken;
6
7
/**
8
 * Class AccessToken
9
 *
10
 * @package Mailxpert\APIBundle\Model
11
 */
12
class AccessToken implements AccessTokenInterface
13
{
14
    protected $id;
15
16
    /**
17
     * @var string
18
     */
19
    protected $accessToken;
20
21
    /**
22
     * @var string
23
     */
24
    protected $refreshToken;
25
26
    /**
27
     * @var int
28
     */
29
    protected $expireAt;
30
31
    /**
32
     * @var int
33
     */
34
35
    protected $refreshTokenExpireAt;
36
37
    /**
38
     * @var string
39
     */
40
    protected $scope;
41
42
    /**
43
     * New Access Token
44
     */
45
    public function __construct()
46
    {
47
        // TODO: Implement __construct() method.
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function __toString()
54
    {
55
        return (string) $this->getAccessToken();
56
    }
57
58
    /**
59
     * @return mixed
60
     */
61
    public function getId()
62
    {
63
        return $this->id;
64
    }
65
66
    /**
67
     * @return string
68
     */
69
    public function getAccessToken()
70
    {
71
        return $this->accessToken;
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    public function getRefreshToken()
78
    {
79
        return $this->refreshToken;
80
    }
81
82
    /**
83
     * @return int
84
     */
85
    public function getExpireAt()
86
    {
87
        return $this->expireAt;
88
    }
89
90
    /**
91
     * @return bool
92
     */
93
    public function isValid()
94
    {
95
        return (bool) (time() < $this->getExpireAt());
96
    }
97
98
    /**
99
     * @return int
100
     */
101
    public function getRefreshTokenExpireAt()
102
    {
103
        return $this->refreshTokenExpireAt;
104
    }
105
106
    /**
107
     * @return string
108
     */
109
    public function getScope()
110
    {
111
        return $this->scope;
112
    }
113
114
    /**
115
     * @param string $accessToken
116
     *
117
     * @return AccessToken
118
     */
119
    public function setAccessToken($accessToken)
120
    {
121
        $this->accessToken = $accessToken;
122
123
        return $this;
124
    }
125
126
    /**
127
     * @param string $refreshToken
128
     *
129
     * @return AccessToken
130
     */
131
    public function setRefreshToken($refreshToken)
132
    {
133
        $this->refreshToken = $refreshToken;
134
135
        return $this;
136
    }
137
138
    /**
139
     * @param int $expireAt
140
     *
141
     * @return AccessToken
142
     */
143
    public function setExpireAt($expireAt)
144
    {
145
        $this->expireAt = $expireAt;
146
147
        return $this;
148
    }
149
150
    /**
151
     * @param int $refreshTokenExpireAt
152
     *
153
     * @return AccessToken
154
     */
155
    public function setRefreshTokenExpireAt($refreshTokenExpireAt)
156
    {
157
        $this->refreshTokenExpireAt = $refreshTokenExpireAt;
158
159
        return $this;
160
    }
161
162
    /**
163
     * @param string|null $scope
164
     *
165
     * @return AccessToken
166
     */
167
    public function setScope($scope = null)
168
    {
169
        $this->scope = $scope;
170
171
        return $this;
172
    }
173
174
    /**
175
     * @param string $scope
176
     *
177
     * @return bool
178
     */
179
    public function hasScope($scope)
180
    {
181
        $scopes = explode(',', $this->getScope());
182
183
        return in_array($scope, $scopes);
184
    }
185
186
    /**
187
     * @return SDKAccessToken
188
     */
189
    public function getSDKAccessToken()
190
    {
191
        return new SDKAccessToken(
192
            $this->getAccessToken(),
193
            $this->getRefreshToken(),
194
            $this->getExpireAt(),
195
            $this->getScope(),
196
            $this->getRefreshTokenExpireAt()
197
        );
198
    }
199
200
201
}
202