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

AccessToken::getIssuedAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 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