Skip to content

Commit 257ce41

Browse files
authored
Merge pull request #292 from TomA-R/phpstan_issues
Fix various codestyle issues
2 parents b1e8767 + 183bdf9 commit 257ce41

File tree

17 files changed

+211
-732
lines changed

17 files changed

+211
-732
lines changed

.phpstan/baseline.neon

Lines changed: 3 additions & 708 deletions
Large diffs are not rendered by default.

src/Bigcommerce/Api/Client.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Client
3535
/**
3636
* Connection instance
3737
*
38-
* @var Connection
38+
* @var Connection|false
3939
*/
4040
private static $connection;
4141

@@ -59,12 +59,19 @@ class Client
5959
* @var string
6060
*/
6161
public static $api_path;
62+
/** @var string The OAuth client ID */
6263
private static $client_id;
64+
/** @var string The store hash */
6365
private static $store_hash;
66+
/** @var string The OAuth Auth-Token */
6467
private static $auth_token;
68+
/** @var string */
6569
private static $client_secret;
70+
/** @var string URL pathname prefix for the V2 API */
6671
private static $stores_prefix = '/stores/%s/v2';
72+
/** @var string The BigCommerce store management API host */
6773
private static $api_url = 'https://api.bigcommerce.com';
74+
/** @var string The BigCommerce merchant login URL */
6875
private static $login_url = 'https://login.bigcommerce.com';
6976

7077
/**
@@ -73,7 +80,7 @@ class Client
7380
*
7481
* Accepts OAuth and (for now!) Basic Auth credentials
7582
*
76-
* @param array $settings
83+
* @param array<string, string> $settings
7784
* @return void
7885
*/
7986
public static function configure($settings)
@@ -94,7 +101,8 @@ public static function configure($settings)
94101
* - auth_token
95102
* - store_hash
96103
*
97-
* @param array $settings
104+
* @param array<string, string> $settings
105+
* @return void
98106
* @throws \Exception
99107
*/
100108
public static function configureOAuth($settings)
@@ -111,7 +119,7 @@ public static function configureOAuth($settings)
111119
self::$auth_token = $settings['auth_token'];
112120
self::$store_hash = $settings['store_hash'];
113121

114-
self::$client_secret = isset($settings['client_secret']) ? $settings['client_secret'] : null;
122+
self::$client_secret = $settings['client_secret'] ?? null;
115123

116124
self::$api_path = self::$api_url . sprintf(self::$stores_prefix, self::$store_hash);
117125
self::$connection = false;
@@ -126,7 +134,8 @@ public static function configureOAuth($settings)
126134
* - username
127135
* - api_key
128136
*
129-
* @param array $settings
137+
* @param array<string, string> $settings
138+
* @return void
130139
* @throws \Exception
131140
*/
132141
public static function configureBasicAuth(array $settings)
@@ -156,6 +165,7 @@ public static function configureBasicAuth(array $settings)
156165
* Note that network faults will always cause an exception to be thrown.
157166
*
158167
* @param bool $option sets the value of this flag
168+
* @return void
159169
*/
160170
public static function failOnError($option = true)
161171
{
@@ -164,6 +174,7 @@ public static function failOnError($option = true)
164174

165175
/**
166176
* Return XML strings from the API instead of building objects.
177+
* @return void
167178
*/
168179
public static function useXml()
169180
{
@@ -173,6 +184,7 @@ public static function useXml()
173184
/**
174185
* Return JSON objects from the API instead of XML Strings.
175186
* This is the default behavior.
187+
* @return void
176188
*/
177189
public static function useJson()
178190
{
@@ -183,6 +195,7 @@ public static function useJson()
183195
* Switch SSL certificate verification on requests.
184196
*
185197
* @param bool $option sets the value of this flag
198+
* @return void
186199
*/
187200
public static function verifyPeer($option = false)
188201
{
@@ -194,6 +207,7 @@ public static function verifyPeer($option = false)
194207
*
195208
* @param string $host host server
196209
* @param int|bool $port port number to use, or false
210+
* @return void
197211
*/
198212
public static function useProxy($host, $port = false)
199213
{
@@ -244,7 +258,8 @@ public static function getConnection()
244258
/**
245259
* Set the HTTP connection object. DANGER: This can screw up your Client!
246260
*
247-
* @param Connection $connection The connection to use
261+
* @param Connection|null $connection The connection to use
262+
* @return void
248263
*/
249264
public static function setConnection(Connection $connection = null)
250265
{
@@ -343,8 +358,8 @@ public static function deleteResource($path)
343358
* Internal method to wrap items in a collection to resource classes.
344359
*
345360
* @param string $resource name of the resource class
346-
* @param array $object object collection
347-
* @return array
361+
* @param mixed $object object collection
362+
* @return Resource[]
348363
*/
349364
private static function mapCollection($resource, $object)
350365
{

src/Bigcommerce/Api/Connection.php

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Bigcommerce\Api;
44

5+
use CurlHandle;
6+
57
/**
68
* HTTP connection.
79
*/
@@ -21,17 +23,17 @@ class Connection
2123
const MEDIA_TYPE_WWW = 'application/x-www-form-urlencoded';
2224

2325
/**
24-
* @var resource cURL resource
26+
* @var CurlHandle cURL resource
2527
*/
2628
private $curl;
2729

2830
/**
29-
* @var array Hash of HTTP request headers.
31+
* @var array<string, string> Hash of HTTP request headers.
3032
*/
3133
private $headers = [];
3234

3335
/**
34-
* @var array Hash of headers from HTTP response
36+
* @var array<string, string> Hash of headers from HTTP response
3537
*/
3638
private $responseHeaders = [];
3739

@@ -78,11 +80,13 @@ class Connection
7880

7981
/**
8082
* Determines whether the response body should be returned as a raw string.
83+
* @var bool
8184
*/
8285
private $rawResponse = false;
8386

8487
/**
8588
* Determines the default content type to use with requests and responses.
89+
* @var string
8690
*/
8791
private $contentType;
8892

@@ -134,6 +138,7 @@ public function useXml($option = true)
134138
* as urlencoded form data.
135139
*
136140
* @param bool $option the new state of this feature
141+
* @return void
137142
*/
138143
public function useUrlEncoded($option = true)
139144
{
@@ -156,6 +161,7 @@ public function useUrlEncoded($option = true)
156161
* as this fails fast, making the HTTP body and headers inaccessible.</em></p>
157162
*
158163
* @param bool $option the new state of this feature
164+
* @return void
159165
*/
160166
public function failOnError($option = true)
161167
{
@@ -167,6 +173,7 @@ public function failOnError($option = true)
167173
*
168174
* @param string $username
169175
* @param string $password
176+
* @return void
170177
*/
171178
public function authenticateBasic($username, $password)
172179
{
@@ -178,6 +185,7 @@ public function authenticateBasic($username, $password)
178185
*
179186
* @param string $clientId
180187
* @param string $authToken
188+
* @return void
181189
*/
182190
public function authenticateOauth($clientId, $authToken)
183191
{
@@ -190,6 +198,7 @@ public function authenticateOauth($clientId, $authToken)
190198
* request takes longer than this to respond.
191199
*
192200
* @param int $timeout number of seconds to wait on a response
201+
* @return void
193202
*/
194203
public function setTimeout($timeout)
195204
{
@@ -202,6 +211,7 @@ public function setTimeout($timeout)
202211
*
203212
* @param string $server
204213
* @param int|bool $port optional port number
214+
* @return void
205215
*/
206216
public function useProxy($server, $port = false)
207217
{
@@ -214,7 +224,8 @@ public function useProxy($server, $port = false)
214224

215225
/**
216226
* @todo may need to handle CURLOPT_SSL_VERIFYHOST and CURLOPT_CAINFO as well
217-
* @param boolean
227+
* @param bool $option Whether to verify the peer's SSL certificate
228+
* @return void
218229
*/
219230
public function verifyPeer($option = false)
220231
{
@@ -226,6 +237,7 @@ public function verifyPeer($option = false)
226237
*
227238
* @param string $header
228239
* @param string $value
240+
* @return void
229241
*/
230242
public function addHeader($header, $value)
231243
{
@@ -236,6 +248,7 @@ public function addHeader($header, $value)
236248
* Remove a header from the request.
237249
*
238250
* @param string $header
251+
* @return void
239252
*/
240253
public function removeHeader($header)
241254
{
@@ -245,7 +258,7 @@ public function removeHeader($header)
245258
/**
246259
* Return the request headers
247260
*
248-
* @return array
261+
* @return array<string, string>
249262
*/
250263
public function getRequestHeaders()
251264
{
@@ -256,6 +269,7 @@ public function getRequestHeaders()
256269
* Get the MIME type that should be used for this request.
257270
*
258271
* Defaults to application/json
272+
* @return string
259273
*/
260274
private function getContentType()
261275
{
@@ -265,6 +279,7 @@ private function getContentType()
265279
/**
266280
* Clear previously cached request data and prepare for
267281
* making a fresh request.
282+
* @return void
268283
*/
269284
private function initializeRequest()
270285
{
@@ -324,6 +339,7 @@ private function handleResponse()
324339
/**
325340
* Return an representation of an error returned by the last request, or false
326341
* if the last request was not an error.
342+
* @return false|string
327343
*/
328344
public function getLastError()
329345
{
@@ -336,6 +352,7 @@ public function getLastError()
336352
*
337353
* Only 301 and 302 redirects are handled. Redirects from POST and PUT requests will
338354
* be converted into GET requests, as per the HTTP spec.
355+
* @return void
339356
*/
340357
private function followRedirectPath()
341358
{
@@ -367,7 +384,7 @@ private function followRedirectPath()
367384
* Make an HTTP GET request to the specified endpoint.
368385
*
369386
* @param string $url URL to retrieve
370-
* @param array|bool $query Optional array of query string parameters
387+
* @param array<string, string>|bool $query Optional array of query string parameters
371388
*
372389
* @return mixed
373390
*/
@@ -498,7 +515,7 @@ public function delete($url)
498515
/**
499516
* Method that appears unused, but is in fact called by curl
500517
*
501-
* @param resource $curl
518+
* @param CurlHandle $curl
502519
* @param string $body
503520
* @return int
504521
*/
@@ -511,7 +528,7 @@ private function parseBody($curl, $body)
511528
/**
512529
* Method that appears unused, but is in fact called by curl
513530
*
514-
* @param resource $curl
531+
* @param CurlHandle $curl
515532
* @param string $headers
516533
* @return int
517534
*/
@@ -580,6 +597,7 @@ public function getHeader($header)
580597

581598
/**
582599
* Return the full list of response headers
600+
* @return array<string, string>
583601
*/
584602
public function getHeaders()
585603
{

0 commit comments

Comments
 (0)