TradeGecko::getAccessTokenRequest()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
1
<?php namespace AlexOsborn\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 TradeGecko extends AbstractProvider
11
{
12
    use ArrayAccessorTrait,
13
        BearerAuthorizationTrait;
14
15
    /**
16
     * Get authorization url to begin OAuth flow
17
     *
18
     * @return string
19
     */
20
    public function getBaseAuthorizationUrl()
21
    {
22
        return 'https://api.tradegecko.com/oauth/authorize';
23
    }
24
25
    /**
26
     * Get access token url to retrieve token
27
     *
28
     * @return string
29
     */
30
    public function getBaseAccessTokenUrl(array $params)
31
    {
32
        return 'https://api.tradegecko.com/oauth/token';
33
    }
34
35
    /**
36
     * Get provider url to fetch user details
37
     *
38
     * @param  AccessToken $token
39
     *
40
     * @return string
41
     */
42
    public function getResourceOwnerDetailsUrl(AccessToken $token)
43
    {
44
        return 'https://api.tradegecko.com/users/current';
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
    protected function getDefaultScopes()
56
    {
57
        return [];
58
    }
59
60
    /**
61
     * Check a provider response for errors.
62
     *
63
     * @throws IdentityProviderException
64
     * @param  ResponseInterface $response
65
     * @param  string $data Parsed response data
66
     * @return void
67
     */
68
    protected function checkResponse(ResponseInterface $response, $data)
69
    {
70
        $errors = [
71
            'error_description',
72
            'error.message',
73
        ];
74
75
        array_map(function ($error) use ($response, $data) {
76
            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...
77
                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...
78
            }
79
        }, $errors);
80
    }
81
82
    /**
83
     * Generate a user object from a successful user details request.
84
     *
85
     * @param object $response
86
     * @param AccessToken $token
87
     * @return League\OAuth2\Client\Provider\ResourceOwnerInterface
88
     */
89
    protected function createResourceOwner(array $response, AccessToken $token)
90
    {
91
        return new TradeGeckoResourceOwner($response);
92
    }
93
94
    /**
95
     * Returns a prepared request for requesting an access token.
96
     *
97
     * @param array $params Query string parameters
98
     * @return Psr\Http\Message\RequestInterface
99
     */
100
    protected function getAccessTokenRequest(array $params)
101
    {
102
        $request = parent::getAccessTokenRequest($params);
103
        $uri = $request->getUri()
104
            ->withUserInfo($this->clientId, $this->clientSecret);
105
106
        return $request->withUri($uri);
107
    }
108
}
109