AccessToken   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getInstanceUrl() 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
     * Constructs an access token.
21
     *
22
     * @param array $options An array of options returned by the service provider
23
     *     in the access token request. The `access_token` option is required.
24
     */
25 4
    public function __construct(array $options)
26
    {
27 4
        parent::__construct($options);
28
29 4
        $this->instanceUrl = $options['instance_url'];
30 4
    }
31
32
    /**
33
     * Returns Salesforce instance URL related to Access Token
34
     *
35
     * @return string
36
     */
37 2
    public function getInstanceUrl()
38
    {
39 2
        return $this->instanceUrl;
40
    }
41
42
    /**
43
     * Returns Organisation ID related to Access Token
44
     *
45
     * @return string|null
46
     */
47 6
    public function getOrgId()
48
    {
49 6
        return preg_match('/' . self::ORG_ID_PREFIX .  '(\w{15}|\w{12})/', $this->getResourceOwnerId(), $result)
50 6
            ? $result[0]
51 6
            : null;
52
    }
53
}
54