Completed
Push — master ( c318d2...b62390 )
by Nikolay
04:29
created

Ecwid   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 12
lcom 0
cbo 5
dl 0
loc 52
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 4
A getBaseAuthorizationUrl() 0 4 1
A getBaseAccessTokenUrl() 0 4 1
A getResourceOwnerDetailsUrl() 0 4 1
A getDefaultScopes() 0 4 1
A checkResponse() 0 6 3
A createResourceOwner() 0 4 1
1
<?php
2
3
namespace Mugnate\OAuth2\Client\Provider;
4
5
6
use League\OAuth2\Client\Provider\AbstractProvider;
7
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
8
use League\OAuth2\Client\Token\AccessToken;
9
use Psr\Http\Message\ResponseInterface;
10
11
class Ecwid extends AbstractProvider
12
{
13
    /**
14
     * @var string Key used in a token response to identify the resource owner.
15
     */
16
    const ACCESS_TOKEN_RESOURCE_OWNER_ID = 'store_id';
17
18
    public function __construct(array $options = [], array $collaborators = [])
19
    {
20
        if (empty($options['clientId'])) {
21
            throw new \InvalidArgumentException('The "clientId" option not set. Please set it.');
22
        } elseif (empty($options['clientSecret'])) {
23
            throw new \InvalidArgumentException('The "clientSecret" option not set. Please set it.');
24
        } elseif (empty($options['redirectUri'])) {
25
            throw new \InvalidArgumentException('The "redirectUri" option not set. Please set it.');
26
        }
27
28
        parent::__construct($options, $collaborators);
29
    }
30
31
    public function getBaseAuthorizationUrl()
32
    {
33
        return 'https://my.ecwid.com/api/oauth/authorize';
34
    }
35
36
    public function getBaseAccessTokenUrl(array $params)
37
    {
38
        return 'https://my.ecwid.com/api/oauth/token';
39
    }
40
41
    public function getResourceOwnerDetailsUrl(AccessToken $token)
42
    {
43
        return 'https://app.ecwid.com/api/v3/' .$token->getResourceOwnerId(). '/profile?token=' . $token->getToken();
44
    }
45
46
    protected function getDefaultScopes()
47
    {
48
        return ['read_store_profile'];
49
    }
50
51
    protected function checkResponse(ResponseInterface $response, $data)
52
    {
53
        if (isset($data['error']) || $response->getStatusCode() != 200) {
54
            throw new IdentityProviderException($data['error'], $response->getStatusCode(), $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...
55
        }
56
    }
57
58
    protected function createResourceOwner(array $response, AccessToken $token)
59
    {
60
        return new EcwidStoreProfile($response);
61
    }
62
}