AccessToken   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 13
c 2
b 0
f 0
lcom 2
cbo 0
dl 0
loc 82
ccs 29
cts 29
cp 1
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 4
A isExpired() 0 4 2
A getExpires() 0 4 1
A getData() 0 4 1
A getScope() 0 4 2
A getToken() 0 4 1
A getRefreshToken() 0 4 1
A getType() 0 4 1
1
<?php
2
3
namespace CommerceGuys\Guzzle\Oauth2;
4
5
class AccessToken
6
{
7
    /** @var string */
8
    protected $token;
9
10
    /** @var \DateTime|null */
11
    protected $expires;
12
13
    /** @var string */
14
    protected $type;
15
16
    /** @var AccessToken|null */
17
    protected $refreshToken;
18
19
    /** @var array */
20
    protected $data;
21
22
    /**
23
     * @param string $token
24
     * @param string $type The token type (from OAuth2 key 'token_type').
25
     * @param array  $data Other token data.
26
     */
27 9
    public function __construct($token, $type, array $data = [])
28
    {
29 9
        $this->token = $token;
30 9
        $this->type = $type;
31 9
        $this->data = $data;
32 9
        if (isset($data['expires'])) {
33 3
            $this->expires = new \DateTime();
34 3
            $this->expires->setTimestamp($data['expires']);
35 9
        } elseif (isset($data['expires_in'])) {
36 6
            $this->expires = new \DateTime();
37 6
            $this->expires->add(new \DateInterval(sprintf('PT%sS', $data['expires_in'])));
38 6
        }
39 9
        if (isset($data['refresh_token'])) {
40 6
            $this->refreshToken = new self($data['refresh_token'], 'refresh_token');
41 6
        }
42 9
    }
43
44
    /** @return bool */
45 5
    public function isExpired()
46
    {
47 5
        return $this->expires !== null && $this->expires->getTimestamp() < time();
48
    }
49
50
    /** @return \DateTime|null */
51 3
    public function getExpires()
52
    {
53 3
        return $this->expires;
54
    }
55
56
    /** @return array */
57 1
    public function getData()
58
    {
59 1
        return $this->data;
60
    }
61
62
    /** @return string */
63 1
    public function getScope()
64
    {
65 1
        return isset($this->data['scope']) ? $this->data['scope'] : '';
66
    }
67
68
    /** @return string */
69 8
    public function getToken()
70
    {
71 8
        return $this->token;
72
    }
73
74
    /** @return AccessToken|null */
75 5
    public function getRefreshToken()
76
    {
77 5
        return $this->refreshToken;
78
    }
79
80
    /** @return string */
81 2
    public function getType()
82
    {
83 2
        return $this->type;
84
    }
85
86
}
87