Completed
Push — master ( 93b2f0...c1cb0e )
by Дмитрий
07:45
created

AccessToken::__construct()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 18
ccs 12
cts 12
cp 1
rs 9.2
cc 4
eloc 9
nc 5
nop 1
crap 4
1
<?php
2
/**
3
 * SocialConnect project
4
 * @author: Patsura Dmitry https://github.com/ovr <[email protected]>
5
 */
6
7
namespace SocialConnect\OAuth2;
8
9
use SocialConnect\Auth\AccessTokenInterface;
10
use SocialConnect\Auth\Provider\Exception\InvalidAccessToken;
11
12
class AccessToken implements AccessTokenInterface
13
{
14
    /**
15
     * @var string
16
     */
17
    protected $token;
18
19
    /**
20
     * @var int|null
21
     */
22
    protected $expires;
23
24
    /**
25
     * @var integer|null
26
     */
27
    protected $uid;
28
29
    /**
30
     * @param array $token
31
     * @throws InvalidAccessToken
32
     */
33 4
    public function __construct(array $token)
34
    {
35 4
        if (!isset($token['access_token'])) {
36 1
            throw new InvalidAccessToken(
37
                'API returned data without access_token field'
38 1
            );
39
        }
40
41 3
        $this->token = $token['access_token'];
42
43 3
        if (isset($token['expires'])) {
44 1
            $this->expires = $token['expires'];
45 1
        }
46
47 3
        if (isset($token['user_id'])) {
48 2
            $this->uid = $token['user_id'];
49 2
        }
50 3
    }
51
52
    /**
53
     * @return string
54
     */
55 3
    public function getToken()
56
    {
57 3
        return $this->token;
58
    }
59
60
    /**
61
     * @param int|null $uid
62
     */
63
    public function setUid($uid)
64
    {
65
        $this->uid = $uid;
66
    }
67
68
    /**
69
     * @return integer
70
     */
71 2
    public function getUserId()
72
    {
73 2
        return $this->uid;
74
    }
75
76
    /**
77
     * @return int|null
78
     */
79 1
    public function getExpires()
80
    {
81 1
        return $this->expires;
82
    }
83
}
84