Bitbucket   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 7
dl 0
loc 110
ccs 26
cts 26
cp 1
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 checkResponse() 0 13 2
A createResourceOwner() 0 4 1
A getAccessTokenRequest() 0 8 1
1
<?php namespace Stevenmaguire\OAuth2\Client\Provider;
2
3
use League\OAuth2\Client\Provider\AbstractProvider;
4
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
5
use League\OAuth2\Client\Token\AccessToken;
6
use League\OAuth2\Client\Tool\ArrayAccessorTrait;
7
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
8
use Psr\Http\Message\ResponseInterface;
9
10
class Bitbucket extends AbstractProvider
11
{
12
    use ArrayAccessorTrait,
13
        BearerAuthorizationTrait;
14
15
    /**
16
     * Get authorization url to begin OAuth flow
17
     *
18
     * @return string
19
     */
20 9
    public function getBaseAuthorizationUrl()
21
    {
22 9
        return 'https://bitbucket.org/site/oauth2/authorize';
23
    }
24
25
    /**
26
     * Get access token url to retrieve token
27
     *
28
     * @return string
29
     */
30 12
    public function getBaseAccessTokenUrl(array $params)
31
    {
32 12
        return 'https://bitbucket.org/site/oauth2/access_token';
33
    }
34
35
    /**
36
     * Get provider url to fetch user details
37
     *
38
     * @param  AccessToken $token
39
     *
40
     * @return string
41
     */
42 6
    public function getResourceOwnerDetailsUrl(AccessToken $token)
43
    {
44 6
        return 'https://api.bitbucket.org/2.0/user';
45
    }
46
47
    /**
48
     * Get the default scopes used by this provider.
49
     *
50
     * This should not be a complete list of all scopes, but the minimum
51
     * required for the provider user interface!
52
     *
53
     * @return array
54
     */
55 6
    protected function getDefaultScopes()
56
    {
57 6
        return [];
58
    }
59
60
    /**
61
     * Returns the string that should be used to separate scopes when building
62
     * the URL for requesting an access token.
63
     *
64
     * @return string Scope separator, defaults to ' '
65
     */
66 9
    protected function getScopeSeparator()
67
    {
68 9
        return ' ';
69
    }
70
71
    /**
72
     * Check a provider response for errors.
73
     *
74
     * @throws IdentityProviderException
75
     * @param  ResponseInterface $response
76
     * @param  string $data Parsed response data
77
     * @return void
78
     */
79 9
    protected function checkResponse(ResponseInterface $response, $data)
80
    {
81
        $errors = [
82 9
            'error_description',
83 3
            'error.message',
84 3
        ];
85
86 9
        array_map(function ($error) use ($response, $data) {
87 9
            if ($message = $this->getValueByKey($data, $error)) {
0 ignored issues
show
Documentation introduced by
$data is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
88 3
                throw new IdentityProviderException($message, $response->getStatusCode(), $response);
0 ignored issues
show
Documentation introduced by
$response is of type object<Psr\Http\Message\ResponseInterface>, but the function expects a array|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
89
            }
90 9
        }, $errors);
91 9
    }
92
93
    /**
94
     * Generate a user object from a successful user details request.
95
     *
96
     * @param object $response
97
     * @param AccessToken $token
98
     * @return League\OAuth2\Client\Provider\ResourceOwnerInterface
99
     */
100 6
    protected function createResourceOwner(array $response, AccessToken $token)
101
    {
102 6
        return new BitbucketResourceOwner($response);
103
    }
104
105
    /**
106
     * Returns a prepared request for requesting an access token.
107
     *
108
     * @param array $params Query string parameters
109
     * @return Psr\Http\Message\RequestInterface
110
     */
111 9
    protected function getAccessTokenRequest(array $params)
112
    {
113 9
        $request = parent::getAccessTokenRequest($params);
114 9
        $uri = $request->getUri()
115 9
            ->withUserInfo($this->clientId, $this->clientSecret);
116
117 9
        return $request->withUri($uri);
118
    }
119
}
120