Imgur   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 5
dl 0
loc 80
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

6 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 checkResponse() 0 10 3
A createResourceOwner() 0 4 1
1
<?php
2
3
namespace AdamPaterson\OAuth2\Client\Provider;
4
5
use League\OAuth2\Client\Provider\AbstractProvider;
6
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
7
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
8
use League\OAuth2\Client\Token\AccessToken;
9
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
10
use Psr\Http\Message\ResponseInterface;
11
12
class Imgur extends AbstractProvider
13
{
14
    use BearerAuthorizationTrait;
15
16
    /**
17
     * Get authorization url to begin OAuth flow
18
     *
19
     * @return string
20
     */
21 6
    public function getBaseAuthorizationUrl()
22
    {
23 6
        return 'https://api.imgur.com/oauth2/authorize';
24
    }
25
26
    /**
27
     * Get access token url to retrieve token
28
     *
29
     * @param array $params
30
     *
31
     * @return string
32
     */
33 12
    public function getBaseAccessTokenUrl(array $params)
34
    {
35 12
        return 'https://api.imgur.com/oauth2/token';
36
    }
37
38
    /**
39
     * Get provider url to fetch user details
40
     *
41
     * @param AccessToken $token
42
     *
43
     * @return string
44
     */
45 3
    public function getResourceOwnerDetailsUrl(AccessToken $token)
46
    {
47 3
        return 'https://api.imgur.com/3/account/me';
48
    }
49
50
    /**
51
     * Get the default scopes used by this provider.
52
     *
53
     * @return array
54
     */
55 6
    protected function getDefaultScopes()
56
    {
57 6
        return [];
58
    }
59
60
    /**
61
     * Check a provider response for errors.
62
     *
63
     * @param ResponseInterface $response
64
     * @param array|string $data
65
     *
66
     * @throws IdentityProviderException
67
     */
68 9
    protected function checkResponse(ResponseInterface $response, $data)
69
    {
70 9
        if ($response->getStatusCode() >= 400) {
71 3
            throw new IdentityProviderException(
72 3
                $data['error'] ?: $response->getReasonPhrase(),
73 3
                $response->getStatusCode(),
74 2
                $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...
75 1
            );
76
        }
77 6
    }
78
79
    /**
80
     * Generate a user object from a successful user details request.
81
     *
82
     * @param array $response
83
     * @param AccessToken $token
84
     *
85
     * @return League\OAuth2\Client\Provider\ResourceOwnerInterface
86
     */
87 3
    protected function createResourceOwner(array $response, AccessToken $token)
88
    {
89 3
        return new ImgurResourceOwner($response);
90
    }
91
}
92