Completed
Pull Request — master (#8)
by
unknown
03:49
created

AccessToken   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 67
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getInstanceUrl() 0 4 1
A getIssuedAt() 0 4 1
A getOrgId() 0 6 2
1
<?php
2
3
namespace Stevenmaguire\OAuth2\Client\Token;
4
5
class AccessToken extends \League\OAuth2\Client\Token\AccessToken
6
{
7
    /**
8
     * All Salesforce Organisation IDs start with this Prefix
9
     */
10
    const ORG_ID_PREFIX = '00D';
11
12
    /**
13
     * Instance URL
14
     *
15
     * @var string
16
     */
17
    private $instanceUrl;
18
    
19
    /**
20
     * Time when the token was issued
21
     *
22
     * @var string
23
     */
24
    private $issuedAt;
25 4
26
    /**
27 4
     * Constructs an access token.
28
     *
29 4
     * @param array $options An array of options returned by the service provider
30 4
     *     in the access token request. The `access_token` option is required.
31
     */
32
    public function __construct(array $options)
33
    {
34
        parent::__construct($options);
35
36
        $this->instanceUrl = $options['instance_url'];
37 2
        $this->issuedAt = $options['issued_at'];
38
    }
39 2
40
    /**
41
     * Returns Salesforce instance URL related to Access Token
42
     *
43
     * @return string
44
     */
45
    public function getInstanceUrl()
46
    {
47 6
        return $this->instanceUrl;
48
    }
49 6
    
50 6
    /**
51 6
     * Returns time when the Access Token was created as UNIX timestamp
52
     *
53
     * @return string
54
     */
55
    public function getIssuedAt()
56
    {
57
        return $this->issuedAt;
58
    }
59
60
    /**
61
     * Returns Organisation ID related to Access Token
62
     *
63
     * @return string|null
64
     */
65
    public function getOrgId()
66
    {
67
        return preg_match('/' . self::ORG_ID_PREFIX .  '(\w{15}|\w{12})/', $this->getResourceOwnerId(), $result)
68
            ? $result[0]
69
            : null;
70
    }
71
}
72