HubSpot   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Test Coverage

Coverage 95.65%

Importance

Changes 0
Metric Value
wmc 11
lcom 2
cbo 6
dl 0
loc 96
ccs 22
cts 23
cp 0.9565
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getBaseAuthorizationUrl() 0 4 1
A getBaseAccessTokenUrl() 0 4 1
A getResourceOwnerDetailsUrl() 0 4 1
A getDefaultScopes() 0 4 1
A getScopeSeparator() 0 4 1
A getAuthorizationHeaders() 0 9 2
A checkResponse() 0 8 3
A createResourceOwner() 0 4 1
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