AccessToken::__construct()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 6.6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 11
nc 6
nop 1
dl 0
loc 22
ccs 6
cts 10
cp 0.6
crap 6.6
rs 9.6111
c 1
b 0
f 0
1
<?php
2
/**
3
 * SocialConnect project
4
 * @author: Patsura Dmitry https://github.com/ovr <[email protected]>
5
 */
6
declare(strict_types=1);
7
8
namespace SocialConnect\OAuth1;
9
10
use SocialConnect\Provider\AccessTokenInterface;
11
use SocialConnect\Provider\Exception\InvalidAccessToken;
12
13
class AccessToken extends \SocialConnect\OAuth1\Token implements AccessTokenInterface
14
{
15
    /**
16
     * @var string|null
17
     */
18
    protected $userId;
19
20
    /**
21
     * @var string
22
     */
23
    protected $screenName;
24
25 7
    public function __construct(array $token)
26
    {
27 7
        if (!isset($token['oauth_token'])) {
28
            throw new InvalidAccessToken(
29
                'API returned data without oauth_token field'
30
            );
31
        }
32
33 7
        if (!isset($token['oauth_token_secret'])) {
34
            throw new InvalidAccessToken(
35
                'API returned data without oauth_token_secret field'
36
            );
37
        }
38
39 7
        parent::__construct($token['oauth_token'], $token['oauth_token_secret']);
40
41 7
        if (isset($token['user_id'])) {
42
            $this->userId = (string) $token['user_id'];
43
        }
44
45 7
        if (isset($token['screen_name'])) {
46
            $this->screenName = $token['screen_name'];
47
        }
48
    }
49
50
    /**
51
     * @param string $userId
52
     */
53 1
    public function setUserId(string $userId)
54
    {
55 1
        $this->userId = $userId;
56
    }
57
58
    /**
59
     * @return string|null
60
     */
61 1
    public function getUserId()
62
    {
63 1
        return $this->userId;
64
    }
65
66
    /**
67
     * @return string
68
     */
69
    public function getScreenName()
70
    {
71
        return $this->screenName;
72
    }
73
74
    /**
75
     * @return string|null
76
     */
77 5
    public function getToken()
78
    {
79
        // It's a key, not a secret
80 5
        return $this->key;
81
    }
82
83
    /**
84
     * @return int|null
85
     */
86
    public function getExpires()
87
    {
88
        // @todo support
89
        return null;
90
    }
91
92
    /**
93
     * {@inheritDoc}
94
     */
95
    public function getEmail()
96
    {
97
        return null;
98
    }
99
}
100