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 ( afd02b...ded9d0 )
by Roman
02:08
created

Shopify::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
crap 2
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 6
    public function __construct($options = [], array $collaborators = [])
31
    {
32 6
        parent::__construct($options, $collaborators);
33
34 6
        if (empty($options['store'])) {
35 3
            $message = 'The "store" option not set. Please set a Store name.';
36 3
            throw new \InvalidArgumentException($message);
37
        }
38
39 6
        $this->store = $options['store'];
40 6
    }
41
42
    /**
43
     * Get authorization url to begin OAuth flow
44
     *
45
     * @return string
46
     */
47 3
    public function getBaseAuthorizationUrl()
48
    {
49 3
        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 6
    public function getBaseAccessTokenUrl(array $params)
60
    {
61 6
        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 6
    public function getResourceOwnerDetailsUrl(AccessToken $token)
72
    {
73 6
        return sprintf(
74 6
            'https://%s.%s/admin/shop.json?access_token=%s',
75 6
            $this->store,
76 6
            self::BASE_SHOPIFY_DOMAIN,
77 6
            $token->getToken()
78 4
        );
79
    }
80
81
    /**
82
     * Get the default scopes used by this provider.
83
     *
84
     * @link https://help.shopify.com/api/getting-started/authentication/oauth#scopes
85
     * @return array
86
     */
87 3
    protected function getDefaultScopes()
88
    {
89
        return [
90 3
            'read_orders',
91
            'read_products'
92 2
        ];
93
    }
94
95
    /**
96
     * Check a provider response for errors.
97
     *
98
     * @throws \Pizdata\OAuth2\Client\Exception\ShopifyIdentityProviderException
99
     * @param  ResponseInterface $response
100
     * @param  array $data
101
     * @return void
102
     */
103 12
    protected function checkResponse(ResponseInterface $response, $data)
104
    {
105
106 12
        if ($response->getStatusCode() == 400) {
107 3
            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...
108
        }
109
110 9
        if (!empty($data['errors'])) {
111 3
            throw new ShopifyIdentityProviderException($data['errors'], 0, $data);
112
        }
113 6
    }
114
115
    /**
116
     * Generate a user object from a successful user details request.
117
     *
118
     * @param array $response
119
     * @param AccessToken $token
120
     * @return League\OAuth2\Client\Provider\ResourceOwnerInterface
121
     */
122 3
    protected function createResourceOwner(array $response, AccessToken $token)
123
    {
124 3
        $store = new ShopifyResourceOwner($response);
125
126 3
        return $store;
127
    }
128
}
129