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 ( 5c8165...9618ad )
by
unknown
62:51 queued 37:54
created

ShopwareClient::__call()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.2098

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 5
cts 7
cp 0.7143
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 2
crap 3.2098
1
<?php
2
3
namespace LeadCommerce\Shopware\SDK;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Handler\CurlHandler;
7
use GuzzleHttp\HandlerStack;
8
use LeadCommerce\Shopware\SDK\Query\AddressQuery;
9
use LeadCommerce\Shopware\SDK\Query\ArticleQuery;
10
use LeadCommerce\Shopware\SDK\Query\CacheQuery;
11
use LeadCommerce\Shopware\SDK\Query\CategoriesQuery;
12
use LeadCommerce\Shopware\SDK\Query\CountriesQuery;
13
use LeadCommerce\Shopware\SDK\Query\CustomerGroupsQuery;
14
use LeadCommerce\Shopware\SDK\Query\CustomerQuery;
15
use LeadCommerce\Shopware\SDK\Query\GenerateArticleImagesQuery;
16
use LeadCommerce\Shopware\SDK\Query\ManufacturersQuery;
17
use LeadCommerce\Shopware\SDK\Query\MediaQuery;
18
use LeadCommerce\Shopware\SDK\Query\OrdersQuery;
19
use LeadCommerce\Shopware\SDK\Query\PropertyGroupsQuery;
20
use LeadCommerce\Shopware\SDK\Query\ShopsQuery;
21
use LeadCommerce\Shopware\SDK\Query\TranslationsQuery;
22
use LeadCommerce\Shopware\SDK\Query\VariantsQuery;
23
use LeadCommerce\Shopware\SDK\Query\VersionQuery;
24
25
/**
26
 * Class ShopwareClient
27
 *
28
 * @author Alexander Mahrt <[email protected]>
29
 * @copyright 2016 LeadCommerce <[email protected]>
30
 *
31
 * @method AddressQuery getAddressQuery()
32
 * @method ArticleQuery getArticleQuery()
33
 * @method CacheQuery getCacheQuery()
34
 * @method CategoriesQuery getCategoriesQuery()
35
 * @method CountriesQuery getCountriesQuery()
36
 * @method CustomerGroupsQuery getCustomerGroupsQuery()
37
 * @method CustomerQuery getCustomerQuery()
38
 * @method GenerateArticleImagesQuery getGenerateArticleImageQuery()
39
 * @method MediaQuery getMediaQuery()
40
 * @method ManufacturersQuery getManufacturersQuery()
41
 * @method OrdersQuery getOrdersQuery()
42
 * @method PropertyGroupsQuery getPropertyGroupsQuery()
43
 * @method ShopsQuery getShopsQuery()
44
 * @method TranslationsQuery getTranslationsQuery()
45
 * @method VariantsQuery getVariantsQuery()
46
 * @method VersionQuery getVersionQuery()
47
 */
48
class ShopwareClient
49
{
50
    const VERSION = '0.0.1';
51
52
    /**
53
     * @var string|null
54
     */
55
    protected $baseUrl;
56
57
    /**
58
     * @var string|null
59
     */
60
    protected $username;
61
62
    /**
63
     * @var string|null
64
     */
65
    protected $apiKey;
66
67
    /**
68
     * @var Client
69
     */
70
    protected $client;
71
72
    /**
73
     * ShopwareClient constructor.
74
     *
75
     * @param $baseUrl
76
     * @param null $username
77
     * @param null $apiKey
78
     */
79 10
    public function __construct($baseUrl, $username = null, $apiKey = null)
80
    {
81 10
        $this->baseUrl = $baseUrl;
82 10
        $this->username = $username;
83 10
        $this->apiKey = $apiKey;
84 10
        $curlHandler = new CurlHandler();
85 10
        $handlerStack = HandlerStack::create($curlHandler);
86 10
        $this->client = new Client([
87 10
            'base_uri' => $this->baseUrl,
88
            'handler'  => $handlerStack
89 10
        ]);
90 10
    }
91
92
    /**
93
     * Does a request.
94
     *
95
     * @param $uri
96
     * @param string $method
97
     * @param null   $body
98
     * @param array  $headers
99
     *
100
     * @return mixed|\Psr\Http\Message\ResponseInterface
101
     */
102 8
    public function request($uri, $method = 'GET', $body = null, $headers = [])
103
    {
104 8
        return $this->client->request($method, $uri, [
105 8
            'json'        => $body,
106 8
            'headers'     => $headers,
107
            'auth'        => [
108 8
                $this->username,
109 8
                $this->apiKey,
110 8
                'digest',
111 8
            ],
112 8
        ]);
113
    }
114
115
    /**
116
     * Magically get the query classes.
117
     *
118
     * @param $name
119
     * @param array $arguments
120
     *
121
     * @return bool
122
     */
123 1
    public function __call($name, $arguments = [])
124
    {
125 1
        if (!preg_match('/^get([a-z]+Query)$/i', $name, $matches)) {
126
            return false;
127
        }
128
129 1
        $className = __NAMESPACE__ . '\\Query\\' . $matches[1];
130
131 1
        if (!class_exists($className)) {
132
            return false;
133
        }
134
135 1
        return new $className($this);
136
    }
137
138
    /**
139
     * @return Client
140
     */
141 1
    public function getClient()
142
    {
143 1
        return $this->client;
144
    }
145
146
    /**
147
     * @param Client $client
148
     *
149
     * @return ShopwareClient
150
     */
151 10
    public function setClient($client)
152
    {
153 10
        $this->client = $client;
154
155 10
        return $this;
156
    }
157
}
158