Passed
Push — master ( c9334a...8a0881 )
by Rutger
13:35
created

Oauth2AccessTokenData   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 56
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 56
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
    protected $data;
0 ignored issues
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
11
    protected $createdAt;
0 ignored issues
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
12
13
    use ArrayAccessTrait;
0 ignored issues
show
Coding Style introduced by
The first trait import statement must be declared on the first non-comment line after the class opening brace
Loading history...
14
15
    public function __construct(array $data)
16
    {
17
        if (empty($data['access_token'])) {
18
            throw new InvalidArgumentException('$data must include key "access_token".');
19
        }
20
21
        $this->data = $data;
22
        $this->createdAt = time();
23
    }
24
25
    public function __serialize()
26
    {
27
        return $this->data;
28
    }
29
30
    public function __unserialize($data)
31
    {
32
        $this->data = $data;
33
    }
34
35
36
    public function getAccessToken()
37
    {
38
        return $this->data['access_token'];
39
    }
40
41
    public function getTokenType()
42
    {
43
        return $this->data['token_type'];
44
    }
45
46
    public function getRawExpiresIn()
47
    {
48
        return $this->data['expires_in'];
49
    }
50
51
    public function getRefreshToken()
52
    {
53
        return $this->data['refresh_token'];
54
    }
55
56
    public function getScope()
57
    {
58
        return $this->data['scope'];
59
    }
60
61
    public function jsonSerialize()
62
    {
63
        return $this->data;
64
    }
65
66
67
}
68