Elance::prepareAccessTokenResponse()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
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 Psr\Http\Message\ResponseInterface;
7
8
class Elance extends AbstractProvider
9
{
10
    /**
11
     * Get authorization url to begin OAuth flow
12
     *
13
     * @return string
14
     */
15 12
    public function getBaseAuthorizationUrl()
16
    {
17 12
        return 'https://api.elance.com/api2/oauth/authorize';
18
    }
19
20
    /**
21
     * Get access token url to retrieve token
22
     *
23
     * @return string
24
     */
25 12
    public function getBaseAccessTokenUrl(array $params)
26
    {
27 12
        return 'https://api.elance.com/api2/oauth/token';
28
    }
29
30
    /**
31
     * Get provider url to fetch user details
32
     *
33
     * @param  AccessToken $token
34
     *
35
     * @return string
36
     */
37 6
    public function getResourceOwnerDetailsUrl(AccessToken $token)
38
    {
39 6
        return 'https://api.elance.com/api2/profiles/my?access_token='.$token;
40
    }
41
42
    /**
43
     * Get the default scopes used by this provider.
44
     *
45
     * This should not be a complete list of all scopes, but the minimum
46
     * required for the provider user interface!
47
     *
48
     * @return string[]
49
     */
50 9
    protected function getDefaultScopes()
51
    {
52 9
        return ['basicInfo'];
53
    }
54
55
    /**
56
     * Prepares an parsed access token response for a grant.
57
     *
58
     * Custom mapping of expiration, etc should be done here. Always call the
59
     * parent method when overloading this method.
60
     *
61
     * @param  mixed $result
62
     * @return array
63
     */
64 9
    protected function prepareAccessTokenResponse(array $result)
65
    {
66 9
        if (isset($result['data'])) {
67 9
            $result = $result['data'];
68 3
        }
69
70 9
        return parent::prepareAccessTokenResponse($result);
71
    }
72
73
    /**
74
     * Check a provider response for errors.
75
     *
76
     * @throws IdentityProviderException
77
     * @param  ResponseInterface $response
78
     * @param  string $data Parsed response data
79
     * @return void
80
     */
81 9
    protected function checkResponse(ResponseInterface $response, $data)
82
    {
83 9
        if (isset($data['errors'])) {
84 3
            throw new IdentityProviderException(
85 3
                $response->getReasonPhrase(),
86 3
                $response->getStatusCode(),
87
                $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...
88 1
            );
89
        }
90 9
    }
91
92
    /**
93
     * Generate a user object from a successful user details request.
94
     *
95
     * @param object $response
96
     * @param AccessToken $token
97
     * @return ElanceResourceOwner
98
     */
99 3
    protected function createResourceOwner(array $response, AccessToken $token)
100
    {
101 3
        return new ElanceResourceOwner($response);
102
    }
103
}
104