xREL   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getBaseAuthorizationUrl() 0 4 1
A getBaseAccessTokenUrl() 0 4 1
A getResourceOwnerDetailsUrl() 0 4 1
A getDefaultScopes() 0 4 1
A createResourceOwner() 0 4 1
B checkResponse() 0 10 5
1
<?php
2
3
namespace xREL\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 League\OAuth2\Client\Tool\BearerAuthorizationTrait;
9
use Psr\Http\Message\ResponseInterface;
10
11
class xREL extends AbstractProvider
12
{
13
    use BearerAuthorizationTrait;
14
15
    /**
16
     * Get authorization url to begin OAuth flow.
17
     *
18
     * @return string
19
     */
20 9
    public function getBaseAuthorizationUrl()
21
    {
22 9
        return 'https://api.xrel.to/v2/oauth2/auth';
23
    }
24
25
    /**
26
     * Get access token url to retrieve token.
27
     *
28
     * @param array $params
29
     *
30
     * @return string
31
     */
32 12
    public function getBaseAccessTokenUrl(array $params)
33
    {
34 12
        return 'https://api.xrel.to/v2/oauth2/token';
35
    }
36
37
    /**
38
     * Get provider url to fetch user details.
39
     *
40
     * @param AccessToken $token
41
     *
42
     * @return string
43
     */
44 6
    public function getResourceOwnerDetailsUrl(AccessToken $token)
45
    {
46 6
        return 'https://api.xrel.to/v2/user/info.json';
47
    }
48
49
    /**
50
     * Get the default scopes used by this provider.
51
     *
52
     * @return array
53
     */
54 6
    protected function getDefaultScopes()
55
    {
56 6
        return [];
57
    }
58
59
    /**
60
     * Check a provider response for errors.
61
     *
62
     * @param ResponseInterface $response
63
     * @param array|string      $data
64
     *
65
     * @throws IdentityProviderException
66
     */
67 9
    protected function checkResponse(ResponseInterface $response, $data)
68
    {
69 9
        if ($response->getStatusCode() >= 400 || isset($data['error_type'])) {
70 3
            throw new IdentityProviderException(
71 3
                $data['error'] ?: $response->getReasonPhrase(),
72 3
                $response->getStatusCode() ?: 0,
73
                $data
74
            );
75
        }
76 9
    }
77
78
    /**
79
     * Generate a user object from a successful user details request.
80
     *
81
     * @param array       $response
82
     * @param AccessToken $token
83
     *
84
     * @return League\OAuth2\Client\Provider\ResourceOwnerInterface
85
     */
86 3
    protected function createResourceOwner(array $response, AccessToken $token)
87
    {
88 3
        return new xRELResourceOwner($response);
89
    }
90
}
91