GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( a4d9c8...a1ccf8 )
by Roman
05:07
created

Shopify::checkResponse()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 5.667

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 2
cts 6
cp 0.3333
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 2
crap 5.667
1
<?php namespace Pizdata\OAuth2\Client\Provider;
2
3
use Psr\Http\Message\ResponseInterface;
4
use League\OAuth2\Client\Token\AccessToken;
5
use League\OAuth2\Client\Provider\AbstractProvider;
6
use Pizdata\OAuth2\Client\Exception\ShopifyIdentityProviderException;
7
8
class Shopify extends AbstractProvider
9
{
10
    /**
11
     * Production Shopify domain.
12
     *
13
     * @const string
14
     */
15
    const BASE_SHOPIFY_DOMAIN = 'myshopify.com';
16
17
    /**
18
     * The store name.
19
     *
20
     * @var string
21
     */
22
    public $store = '';
23
24
    /**
25
     * @param array $options
26
     * @param array $collaborators
27
     *
28
     * @throws \InvalidArgumentException
29
     */
30 9
    public function __construct($options = [], array $collaborators = [])
31
    {
32 9
        parent::__construct($options, $collaborators);
33
34 9
        if (empty($options['store'])) {
35
            $message = 'The "store" option not set. Please set a Store name.';
36
            throw new \InvalidArgumentException($message);
37
        }
38
39 9
        $this->store = $options['store'];
40 9
    }
41
42
    /**
43
     * Get authorization url to begin OAuth flow
44
     *
45
     * @return string
46
     */
47 6
    public function getBaseAuthorizationUrl()
48
    {
49 6
        return sprintf('https://%s.%s/admin/oauth/authorize', $this->store, self::BASE_SHOPIFY_DOMAIN);
50
    }
51
52
    /**
53
     * Get access token url to retrieve token
54
     *
55
     * @param  array $params
56
     *
57
     * @return string
58
     */
59 3
    public function getBaseAccessTokenUrl(array $params)
60
    {
61 3
        return sprintf('https://%s.%s/admin/oauth/access_token', $this->store, self::BASE_SHOPIFY_DOMAIN);
62
    }
63
64
    /**
65
     * Get provider url to fetch user details
66
     *
67
     * @param  AccessToken $token
68
     *
69
     * @return string
70
     */
71
    public function getResourceOwnerDetailsUrl(AccessToken $token)
72
    {
73
        return sprintf(
74
            'https://%s.%s/admin/shop.json?access_token=%s',
75
            $this->store, self::BASE_SHOPIFY_DOMAIN,
76
            $token->getToken()
77
        );
78
    }
79
80
    /**
81
     * Get the default scopes used by this provider.
82
     *
83
     * @link https://help.shopify.com/api/getting-started/authentication/oauth#scopes
84
     * @return array
85
     */
86 6
    protected function getDefaultScopes()
87
    {
88
        return [
89 6
            'read_orders',
90
            'read_products'
91 4
        ];
92
    }
93
94
    /**
95
     * Check a provider response for errors.
96
     *
97
     * @throws IdentityProviderException
98
     * @param  ResponseInterface $response
99
     * @param  array $data
100
     * @return void
101
     */
102 2
    protected function checkResponse(ResponseInterface $response, $data)
103
    {
104
        if ($response->getStatusCode() == 400) {
105
            throw new ShopifyIdentityProviderException($data, 0, $response->getReasonPhrase());
0 ignored issues
show
Documentation introduced by
$data is of type array, but the function expects a 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...
106
        }
107
108
        if (!empty($data['errors'])) {
109
            throw new ShopifyIdentityProviderException($data['errors'], 0, $data);
110
        }
111 2
    }
112
113
    /**
114
     * Generate a user object from a successful user details request.
115
     *
116
     * @param array $response
117
     * @param AccessToken $token
118
     * @return League\OAuth2\Client\Provider\ResourceOwnerInterface
119
     */
120
    protected function createResourceOwner(array $response, AccessToken $token)
121
    {
122
        $store = new ShopifyResourceOwner($response);
123
124
        return $store;
125
    }
126
}
127