Completed
Push — master ( 13ebbb...80a6f6 )
by Hassan
02:33
created

Psn::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Larabros\OAuth2\Client\Provider;
4
5
use League\OAuth2\Client\Provider\AbstractProvider;
6
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
7
use League\OAuth2\Client\Token\AccessToken;
8
use Psr\Http\Message\ResponseInterface;
9
10
class Psn extends AbstractProvider
11
{
12
    /**
13
     * @var string Key used in the access token response to identify the resource owner.
14
     */
15
    const ACCESS_TOKEN_RESOURCE_OWNER_ID = 'accountId';
16
17
    /**
18
     * {@inheritDoc}
19
     */
20 6
    public function getBaseAuthorizationUrl()
21
    {
22 6
        return 'https://auth.api.sonyentertainmentnetwork.com/2.0/oauth/authorize';
23
    }
24
25
    /**
26
     * {@inheritDoc}
27
     */
28 12
    public function getBaseAccessTokenUrl(array $params)
29
    {
30 12
        return 'https://auth.api.sonyentertainmentnetwork.com/2.0/oauth/token';
31
    }
32
33
    /**
34
     * {@inheritDoc}
35
     */
36 2
    public function getResourceOwnerDetailsUrl(AccessToken $token)
37
    {
38 2
        return 'https://vl.api.np.km.playstation.net/vl/api/v1/mobile/users/me/info';
39
    }
40
41
    /**
42
     * {@inheritDoc}
43
     */
44 4
    protected function getDefaultScopes()
45
    {
46 4
        return ['psn:s2s'];
47
    }
48
49
    /**
50
     * {@inheritDoc}
51
     */
52 10
    protected function checkResponse(ResponseInterface $response, $data)
53
    {
54 10
        if (isset($data['error'])) {
55
56 4
            if (is_array($data['error'])) {
57 2
                throw new IdentityProviderException(
58 2
                    $data['error']['messageKey'].': '.$data['error']['message'] ?: $response->getReasonPhrase(),
59 2
                    $data['error']['code'] ?: $response->getStatusCode(),
60
                    $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...
61 2
                );
62
            }
63
64 2
            throw new IdentityProviderException(
65 2
                $data['error_description'] ?: $response->getReasonPhrase(),
66 2
                $data['error_code'] ?: $response->getStatusCode(),
67
                $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...
68 2
            );
69
        }
70 6
    }
71
72
    /**
73
     * {@inheritDoc}
74
     */
75 2
    protected function createResourceOwner(array $response, AccessToken $token)
76
    {
77 2
        return new PsnResourceOwner($response);
78
    }
79
80
    /**
81
     * {@inheritDoc}
82
     */
83 4
    protected function getAuthorizationHeaders($token = null)
84
    {
85
        return [
86 4
            'Bearer'            => $token,
87 4
            'X-NP-ACCESS-TOKEN' => $token,
88 4
        ];
89
    }
90
}
91