Completed
Push — master ( 67e17f...7818e1 )
by Oleg
03:13
created

EveOnline::checkResponse()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 5

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 27
ccs 17
cts 17
cp 1
rs 8.439
cc 5
eloc 16
nc 4
nop 2
crap 5
1
<?php
2
3
namespace Evelabs\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 EveOnline extends AbstractProvider
13
{
14
    use BearerAuthorizationTrait;
15
16
17
    /**
18
     * Default scopes
19
     *
20
     * @var array
21
     */
22
    public $defaultScopes = [];
23
24
    /**
25
     * Get the string used to separate scopes.
26
     *
27
     * @return string
28
     */
29 9
    protected function getScopeSeparator()
30
    {
31 9
        return ' ';
32
    }
33
34
    /**
35
     * Returns the base URL for authorizing a client.
36
     *
37
     * Eg. https://oauth.service.com/authorize
38
     *
39
     * @return string
40
     */
41 9
    public function getBaseAuthorizationUrl()
42
    {
43 9
        return 'https://login.eveonline.com/oauth/authorize';
44
    }
45
46
    /**
47
     * Returns the base URL for requesting an access token.
48
     *
49
     * Eg. https://oauth.service.com/token
50
     *
51
     * @param array $params
52
     * @return string
53
     */
54 18
    public function getBaseAccessTokenUrl(array $params)
55
    {
56 18
        return 'https://login.eveonline.com/oauth/token';
57
    }
58
59
    /**
60
     * Returns the URL for requesting the resource owner's details.
61
     *
62
     * @param AccessToken $token
63
     * @return string
64
     */
65 3
    public function getResourceOwnerDetailsUrl(AccessToken $token)
66
    {
67 3
        return 'https://login.eveonline.com/oauth/verify';
68
    }
69
70
    /**
71
     * Returns the default scopes used by this provider.
72
     *
73
     * This should only be the scopes that are required to request the details
74
     * of the resource owner, rather than all the available scopes.
75
     *
76
     * @return array
77
     */
78 6
    protected function getDefaultScopes()
79
    {
80 6
        return $this->defaultScopes;
81
    }
82
83
    /**
84
     * Checks a provider response for errors.
85
     *
86
     * @throws IdentityProviderException
87
     * @param  ResponseInterface $response
88
     * @param  array|string $data Parsed response data
89
     * @return void
90
     */
91 15
    protected function checkResponse(ResponseInterface $response, $data)
92
    {
93
94 15
        if (isset($data['exceptionType'])) {
95 3
            throw new IdentityProviderException(
96 3
                isset($data['message']) ? $data['message'] : $response->getReasonPhrase(),
97 3
                $response->getStatusCode(),
98
                $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...
99 2
            );
100
        }
101
102 12
        if (false === is_array($data)) {
103 3
            throw new IdentityProviderException(
104 3
                $response->getReasonPhrase(),
105 3
                $response->getStatusCode(),
106
                $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...
107 2
            );
108
        }
109
110 9
        if (isset($data['error'])) {
111 3
            throw new IdentityProviderException(
112 3
                $data['error_description'],
113 3
                $response->getStatusCode(),
114
                $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...
115 2
            );
116
        }
117 6
    }
118
119
    /**
120
     * Generates a resource owner object from a successful resource owner
121
     * details request.
122
     *
123
     * @param  array $response
124
     * @param  AccessToken $token
125
     * @return ResourceOwnerInterface
126
     */
127 3
    protected function createResourceOwner(array $response, AccessToken $token)
128
    {
129 3
        return new EveOnlineResourceOwner($response);
130
    }
131
}
132