AbstractGuardian   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 5
dl 0
loc 86
ccs 29
cts 29
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getScopeSeparator() 0 4 1
A getAuthorizationParameters() 0 9 1
A getDefaultHeaders() 0 6 1
A getAccessTokenBody() 0 4 1
A getAccessTokenOptions() 0 13 1
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\GuardianIdentityProviderException;
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
abstract class AbstractGuardian extends AbstractProvider
12
{
13
    use BearerAuthorizationTrait;
14
15
    /**
16
     * @inheritdoc
17
     */
18 6
    protected function getScopeSeparator()
19
    {
20 6
        return ' ';
21
    }
22
23
    /**
24
     * @inheritdoc
25
     */
26 6
    protected function getAuthorizationParameters(array $options)
27
    {
28 6
        return array_merge(
29 6
            parent::getAuthorizationParameters($options),
30
            [
31 6
                'client_secret' => $this->clientSecret
32 2
            ]
33 2
        );
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39 12
    protected function getDefaultHeaders()
40
    {
41
        return [
42 8
            'accept' => 'application/json'
43 4
        ];
44
    }
45
46
    /**
47
     * Returns the request body for requesting an access token.
48
     *
49
     * @param  array $params
50
     * @return string
51
     */
52 12
    protected function getAccessTokenBody(array $params)
53
    {
54 12
        return json_encode(array_filter($params));
55
    }
56
57
    /**
58
     * Builds request options used for requesting an access token.
59
     *
60
     * @param  array $params
61
     * @return array
62
     */
63 12
    protected function getAccessTokenOptions(array $params)
64
    {
65 12
        $option = array_merge(
66 12
            parent::getAccessTokenOptions($params),
67
            [
68 8
                'headers' => [
69
                    'content-type' => 'application/json'
70 4
                ]
71 4
            ]
72 4
        );
73
74 12
        return $option;
75
    }
76
77
    /**
78
     * @inheritdoc
79
     */
80 12
    protected function checkResponse(ResponseInterface $response, $data)
81
    {
82 12
        if ($response->getStatusCode() >= 400) {
83 3
            throw GuardianIdentityProviderException::clientException($response, $data);
0 ignored issues
show
Bug introduced by
It seems like $data defined by parameter $data on line 80 can also be of type string; however, Flipbox\OAuth2\Client\Pr...tion::clientException() does only seem to accept array, 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...
84 9
        } elseif (isset($data['error'])) {
85 3
            throw GuardianIdentityProviderException::oauthException($response, $data);
0 ignored issues
show
Bug introduced by
It seems like $data defined by parameter $data on line 80 can also be of type string; however, Flipbox\OAuth2\Client\Pr...ption::oauthException() does only seem to accept array, 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...
86
        }
87 6
    }
88
89
    /**
90
     * @inheritdoc
91
     */
92 3
    protected function createResourceOwner(array $response, AccessToken $token)
93
    {
94 3
        return new GuardianResourceOwner($response);
95
    }
96
}
97