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 ( d6ef0b...33031e )
by Mohamed
20:31 queued 16:33
created

ShopwareClient::getClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Neta\Shopware\SDK;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\HandlerStack;
7
use GuzzleHttp\Handler\CurlHandler;
8
use Neta\Shopware\SDK\Query\CacheQuery;
9
use Neta\Shopware\SDK\Query\MediaQuery;
10
use Neta\Shopware\SDK\Query\ShopsQuery;
11
use Neta\Shopware\SDK\Query\OrdersQuery;
12
use Neta\Shopware\SDK\Query\AddressQuery;
13
use Neta\Shopware\SDK\Query\ArticleQuery;
14
use Neta\Shopware\SDK\Query\VersionQuery;
15
use Neta\Shopware\SDK\Query\CustomerQuery;
16
use Neta\Shopware\SDK\Query\VariantsQuery;
17
use Neta\Shopware\SDK\Query\CountriesQuery;
18
use Neta\Shopware\SDK\Query\CategoriesQuery;
19
use Neta\Shopware\SDK\Query\TranslationsQuery;
20
use Neta\Shopware\SDK\Query\ManufacturersQuery;
21
use Neta\Shopware\SDK\Query\CustomerGroupsQuery;
22
use Neta\Shopware\SDK\Query\PropertyGroupsQuery;
23
use Neta\Shopware\SDK\Query\GenerateArticleImagesQuery;
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 14
    public function __construct($baseUrl, $username = null, $apiKey = null, array $guzzleOptions = [])
80
    {
81 14
        $this->baseUrl = $baseUrl;
82 14
        $this->username = $username;
83 14
        $this->apiKey = $apiKey;
84 14
        $curlHandler = new CurlHandler();
85 14
        $handlerStack = HandlerStack::create($curlHandler);
86
87 14
        $guzzleOptions = array_merge($guzzleOptions, [
88 14
            'base_uri' => $this->baseUrl,
89 14
            'handler'  => $handlerStack,
90
        ]);
91 14
        $this->client = new Client($guzzleOptions);
92 14
    }
93
94
    /**
95
     * Does a request.
96
     *
97
     * @param        $uri
98
     * @param string $method
99
     * @param null   $body
100
     * @param array  $headers
101
     *
102
     * @return mixed|\Psr\Http\Message\ResponseInterface
103
     */
104 12
    public function request($uri, $method = 'GET', $body = null, $headers = [])
105
    {
106 12
        return $this->client->request($method, $uri, [
107 12
            'json'    => $body,
108 12
            'headers' => $headers,
109
            'auth'    => [
110 12
                $this->username,
111 12
                $this->apiKey,
112 12
                'digest',
113
            ],
114
        ]);
115
    }
116
117
    /**
118
     * Magically get the query classes.
119
     *
120
     * @param       $name
121
     * @param array $arguments
122
     *
123
     * @return bool
124
     */
125 1
    public function __call($name, $arguments = [])
126
    {
127 1
        if (! preg_match('/^get([a-z]+Query)$/i', $name, $matches)) {
128
            return false;
129
        }
130
131 1
        $className = __NAMESPACE__ . '\\Query\\' . $matches[1];
132
133 1
        if (! class_exists($className)) {
134
            return false;
135
        }
136
137 1
        return new $className($this);
138
    }
139
140
    /**
141
     * @return Client
142
     */
143 1
    public function getClient()
144
    {
145 1
        return $this->client;
146
    }
147
148
    /**
149
     * @param Client $client
150
     *
151
     * @return ShopwareClient
152
     */
153 14
    public function setClient($client)
154
    {
155 14
        $this->client = $client;
156
157 14
        return $this;
158
    }
159
}
160