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

Oauth2AccessTokenData::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
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