Oauth2AccessTokenData   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 16
c 1
b 0
f 0
dl 0
loc 63
ccs 0
cts 21
cp 0
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getScope() 0 3 1
A jsonSerialize() 0 3 1
A __unserialize() 0 3 1
A getRefreshToken() 0 3 1
A __construct() 0 8 2
A getTokenType() 0 3 1
A getAccessToken() 0 3 1
A __serialize() 0 3 1
A getRawExpiresIn() 0 3 1
1
<?php
2
3
namespace rhertogh\Yii2Oauth2Server\components\server\tokens;
4
5
use yii\base\ArrayAccessTrait;
6
use yii\base\InvalidArgumentException;
7
8
class Oauth2AccessTokenData implements \IteratorAggregate, \ArrayAccess, \Countable, \JsonSerializable
9
{
10
    use ArrayAccessTrait;
11
12
    /**
13
     * @var array
14
     */
15
    protected $data;
16
17
    /**
18
     * @var int
19
     */
20
    protected $createdAt;
21
22
    public function __construct(array $data)
23
    {
24
        if (empty($data['access_token'])) {
25
            throw new InvalidArgumentException('$data must include key "access_token".');
26
        }
27
28
        $this->data = $data;
29
        $this->createdAt = time();
30
    }
31
32
    public function __serialize()
33
    {
34
        return $this->data;
35
    }
36
37
    public function __unserialize($data)
38
    {
39
        $this->data = $data;
40
    }
41
42
43
    public function getAccessToken()
44
    {
45
        return $this->data['access_token'];
46
    }
47
48
    public function getTokenType()
49
    {
50
        return $this->data['token_type'];
51
    }
52
53
    public function getRawExpiresIn()
54
    {
55
        return $this->data['expires_in'];
56
    }
57
58
    public function getRefreshToken()
59
    {
60
        return $this->data['refresh_token'];
61
    }
62
63
    public function getScope()
64
    {
65
        return $this->data['scope'];
66
    }
67
68
    public function jsonSerialize()
69
    {
70
        return $this->data;
71
    }
72
}
73