Completed
Push — master ( ab58ed...829fed )
by Дмитрий
04:32
created

AccessToken   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
lcom 0
cbo 1
dl 0
loc 72
ccs 21
cts 21
cp 1
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getToken() 0 4 1
A getUserId() 0 4 1
A __construct() 0 18 4
A getExpires() 0 4 1
A setUid() 0 4 1
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 5
    public function __construct(array $token)
34
    {
35 5
        if (!isset($token['access_token'])) {
36 1
            throw new InvalidAccessToken(
37
                'API returned data without access_token field'
38 1
            );
39
        }
40
41 4
        $this->token = $token['access_token'];
42
43 4
        if (isset($token['expires'])) {
44 1
            $this->expires = $token['expires'];
45 1
        }
46
47 4
        if (isset($token['user_id'])) {
48 2
            $this->uid = $token['user_id'];
49 2
        }
50 4
    }
51
52
    /**
53
     * @return string
54
     */
55 4
    public function getToken()
56
    {
57 4
        return $this->token;
58
    }
59
60
    /**
61
     * @param int|null $uid
62
     */
63 1
    public function setUid($uid)
64
    {
65 1
        $this->uid = $uid;
66 1
    }
67
68
    /**
69
     * @return integer
70
     */
71 3
    public function getUserId()
72
    {
73 3
        return $this->uid;
74
    }
75
76
    /**
77
     * @return int|null
78
     */
79 2
    public function getExpires()
80
    {
81 2
        return $this->expires;
82
    }
83
}
84