AccessTokenTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 34
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setAccessToken() 0 4 1
A getAccessToken() 0 12 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipboxfactory/patron-hubspot/blob/master/LICENSE
6
 * @link       https://github.com/flipboxfactory/patron-hubspot/
7
 */
8
9
namespace flipbox\patron\hubspot\connections;
10
11
use flipbox\patron\Patron;
12
use League\OAuth2\Client\Token\AccessToken;
13
use League\OAuth2\Client\Token\AccessTokenInterface;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
trait AccessTokenTrait
20
{
21
    use ProviderTrait;
22
23
    /**
24
     * @var AccessTokenInterface|AccessToken|null
25
     */
26
    private $accessToken;
27
28
    /**
29
     * @param AccessTokenInterface|AccessToken $accessToken
30
     */
31
    public function setAccessToken(AccessTokenInterface $accessToken)
32
    {
33
        $this->accessToken = $accessToken;
34
    }
35
36
    /**
37
     * @return AccessTokenInterface|AccessToken
38
     * @throws \yii\base\InvalidConfigException
39
     */
40
    public function getAccessToken(): AccessTokenInterface
41
    {
42
        if (!$this->accessToken instanceof AccessTokenInterface) {
43
            $token = Patron::getInstance()->getTokens([
44
                'provider' => $this->getProvider()
45
            ])->one();
46
47
            $this->accessToken = $token;
48
        }
49
50
        return $this->accessToken;
51
    }
52
}
53