Psn   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 13
c 3
b 1
f 0
lcom 0
cbo 3
dl 0
loc 80
ccs 26
cts 26
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getBaseAccessTokenUrl() 0 4 1
A getResourceOwnerDetailsUrl() 0 4 1
A getDefaultScopes() 0 4 1
A getBaseAuthorizationUrl() 0 4 1
B checkResponse() 0 18 7
A createResourceOwner() 0 4 1
A getAuthorizationHeaders() 0 7 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
/**
11
 * An OAuth2 provider class for PSN.
12
 *
13
 * @package    OAuth2
14
 * @author     Hassan Khan <[email protected]>
15
 * @link       https://github.com/larabros/oauth2-psn
16
 * @license    MIT
17
 */
18
class Psn extends AbstractProvider
19
{
20
    /**
21
     * @var string Key used in the access token response to identify the resource owner.
22
     */
23
    const ACCESS_TOKEN_RESOURCE_OWNER_ID = 'accountId';
24
25
    /**
26
     * {@inheritDoc}
27
     */
28 6
    public function getBaseAuthorizationUrl()
29
    {
30 6
        return 'https://auth.api.sonyentertainmentnetwork.com/2.0/oauth/authorize';
31
    }
32
33
    /**
34
     * {@inheritDoc}
35
     */
36 12
    public function getBaseAccessTokenUrl(array $params)
37
    {
38 12
        return 'https://auth.api.sonyentertainmentnetwork.com/2.0/oauth/token';
39
    }
40
41
    /**
42
     * {@inheritDoc}
43
     */
44 2
    public function getResourceOwnerDetailsUrl(AccessToken $token)
45
    {
46 2
        return 'https://vl.api.np.km.playstation.net/vl/api/v1/mobile/users/me/info';
47
    }
48
49
    /**
50
     * {@inheritDoc}
51
     */
52 4
    protected function getDefaultScopes()
53
    {
54 4
        return ['psn:s2s'];
55
    }
56
57
    /**
58
     * {@inheritDoc}
59
     */
60 10
    protected function checkResponse(ResponseInterface $response, $data)
61
    {
62 10
        if (isset($data['error'])) {
63 4
            if (is_array($data['error'])) {
64 2
                throw new IdentityProviderException(
65 2
                    $data['error']['messageKey'].': '.$data['error']['message'] ?: $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
71 2
            throw new IdentityProviderException(
72 2
                $data['error_description'] ?: $response->getReasonPhrase(),
73 2
                $data['error_code'] ?: $response->getStatusCode(),
74
                $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 2
            );
76
        }
77 6
    }
78
79
    /**
80
     * {@inheritDoc}
81
     */
82 2
    protected function createResourceOwner(array $response, AccessToken $token)
83
    {
84 2
        return new PsnResourceOwner($response);
85
    }
86
87
    /**
88
     * {@inheritDoc}
89
     */
90 4
    protected function getAuthorizationHeaders($token = null)
91
    {
92
        return [
93 4
            'Bearer'            => $token,
94 4
            'X-NP-ACCESS-TOKEN' => $token,
95 4
        ];
96
    }
97
}
98