Completed
Push — master ( 558225...41ceb4 )
by Nate
02:11
created

HubSpot::getAuthorizationHeaders()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 4
cts 5
cp 0.8
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2.032
1
<?php
2
3
namespace Flipbox\OAuth2\Client\Provider;
4
5
use Flipbox\OAuth2\Client\Provider\Exception\HubSpotIdentityProviderException;
6
use League\OAuth2\Client\Provider\AbstractProvider;
7
use League\OAuth2\Client\Token\AccessToken;
8
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
9
use Psr\Http\Message\ResponseInterface;
10
11
class HubSpot extends AbstractProvider
12
{
13
    use BearerAuthorizationTrait;
14
15
    /**
16
     * Domain
17
     *
18
     * @var string
19
     */
20
    public $domain = 'https://app.hubspot.com';
21
22
    /**
23
     * Api domain
24
     *
25
     * @var string
26
     */
27
    public $apiDomain = 'https://api.hubapi.com';
28
29
    /**
30
     * @var array
31
     */
32
    protected $defaultScopes = [];
33
34
    /**
35
     * @inheritdoc
36
     */
37 9
    public function getBaseAuthorizationUrl()
38
    {
39 9
        return $this->domain . '/oauth/authorize';
40
    }
41
42
    /**
43
     * @inheritdoc
44
     */
45 15
    public function getBaseAccessTokenUrl(array $params)
46
    {
47 15
        return $this->apiDomain . '/oauth/v1/token';
48
    }
49
50
    /**
51
     * @inheritdoc
52
     */
53 3
    public function getResourceOwnerDetailsUrl(AccessToken $token)
54
    {
55 3
        return $this->apiDomain . '/oauth/v1/access-tokens/' . $token->getToken();
56
    }
57
58
    /**
59
     * @inheritdoc
60
     */
61 6
    protected function getDefaultScopes()
62
    {
63 6
        return $this->defaultScopes;
64
    }
65
66
    /**
67
     * @inheritdoc
68
     */
69 9
    protected function getScopeSeparator()
70
    {
71 9
        return ' ';
72
    }
73
74
    /**
75
     * @inheritdoc
76
     */
77 3
    protected function getAuthorizationHeaders($token = null)
78
    {
79 3
        if ($token === null) {
80
            return [];
81
        }
82
        return [
83 3
            'Authorization' => sprintf("Bearer %s", $token)
84 1
        ];
85
    }
86
87
    /**
88
     * @inheritdoc
89
     */
90 12
    protected function checkResponse(ResponseInterface $response, $data)
91
    {
92 12
        if ($response->getStatusCode() >= 400) {
93 3
            throw HubSpotIdentityProviderException::clientException($response, $data);
0 ignored issues
show
Bug introduced by
It seems like $data defined by parameter $data on line 90 can also be of type array; however, Flipbox\OAuth2\Client\Pr...tion::clientException() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
94 9
        } elseif (isset($data['error'])) {
95 3
            throw HubSpotIdentityProviderException::oauthException($response, $data);
0 ignored issues
show
Bug introduced by
It seems like $data defined by parameter $data on line 90 can also be of type array; however, Flipbox\OAuth2\Client\Pr...ption::oauthException() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
96
        }
97 6
    }
98
99
    /**
100
     * @inheritdoc
101
     */
102 3
    protected function createResourceOwner(array $response, AccessToken $token)
103
    {
104 3
        return new HubSpotResourceOwner($response);
105
    }
106
}
107