Skip to content

Commit 6a25425

Browse files
committed
Merge pull request #141 from bc-bfenton/cleanup
Cleanup
2 parents 1b0302d + 13915b7 commit 6a25425

25 files changed

Lines changed: 288 additions & 210 deletions

src/Bigcommerce/Api/Client.php

Lines changed: 84 additions & 65 deletions
Large diffs are not rendered by default.

src/Bigcommerce/Api/Connection.php

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ public function __construct()
9191
/**
9292
* Controls whether requests and responses should be treated
9393
* as XML. Defaults to false (using JSON).
94+
*
95+
* @param bool $option the new state of this feature
9496
*/
9597
public function useXml($option = true)
9698
{
@@ -109,6 +111,8 @@ public function useXml($option = true)
109111
*
110112
* <p><em>Note that this doesn't use the builtin CURL_FAILONERROR option,
111113
* as this fails fast, making the HTTP body and headers inaccessible.</em></p>
114+
*
115+
* @param bool $option the new state of this feature
112116
*/
113117
public function failOnError($option = true)
114118
{
@@ -117,6 +121,9 @@ public function failOnError($option = true)
117121

118122
/**
119123
* Sets the HTTP basic authentication.
124+
*
125+
* @param string $username
126+
* @param string $password
120127
*/
121128
public function authenticate($username, $password)
122129
{
@@ -137,6 +144,9 @@ public function setTimeout($timeout)
137144

138145
/**
139146
* Set a proxy server for outgoing requests to tunnel through.
147+
*
148+
* @param string $server
149+
* @param int|bool $port optional port number
140150
*/
141151
public function useProxy($server, $port = false)
142152
{
@@ -249,7 +259,7 @@ public function getLastError()
249259
}
250260

251261
/**
252-
* Recursively follow redirect until an OK response is recieved or
262+
* Recursively follow redirect until an OK response is received or
253263
* the maximum redirects limit is reached.
254264
*
255265
* Only 301 and 302 redirects are handled. Redirects from POST and PUT requests will
@@ -260,9 +270,7 @@ private function followRedirectPath()
260270
$this->redirectsFollowed++;
261271

262272
if ($this->getStatus() == 301 || $this->getStatus() == 302) {
263-
264273
if ($this->redirectsFollowed < $this->maxRedirects) {
265-
266274
$location = $this->getHeader('Location');
267275
$forwardTo = parse_url($location);
268276

@@ -286,6 +294,11 @@ private function followRedirectPath()
286294

287295
/**
288296
* Make an HTTP GET request to the specified endpoint.
297+
*
298+
* @param string $url URL to retrieve
299+
* @param array|bool $query Optional array of query string parameters
300+
*
301+
* @return mixed
289302
*/
290303
public function get($url, $query = false)
291304
{
@@ -305,6 +318,11 @@ public function get($url, $query = false)
305318

306319
/**
307320
* Make an HTTP POST request to the specified endpoint.
321+
*
322+
* @param string $url URL to which we send the request
323+
* @param mixed $body Data payload (JSON string or raw data)
324+
*
325+
* @return mixed
308326
*/
309327
public function post($url, $body)
310328
{
@@ -328,8 +346,8 @@ public function post($url, $body)
328346
/**
329347
* Make an HTTP HEAD request to the specified endpoint.
330348
*
331-
* @param $url
332-
* @return bool|mixed|string
349+
* @param string $url URL to which we send the request
350+
* @return mixed
333351
*/
334352
public function head($url)
335353
{
@@ -349,9 +367,9 @@ public function head($url)
349367
* Requires a tmpfile() handle to be opened on the system, as the cURL
350368
* API requires it to send data.
351369
*
352-
* @param $url
353-
* @param $body
354-
* @return bool|mixed|string
370+
* @param string $url URL to which we send the request
371+
* @param mixed $body Data payload (JSON string or raw data)
372+
* @return mixed
355373
*/
356374
public function put($url, $body)
357375
{
@@ -383,8 +401,8 @@ public function put($url, $body)
383401
/**
384402
* Make an HTTP DELETE request to the specified endpoint.
385403
*
386-
* @param $url
387-
* @return bool|mixed|string
404+
* @param string $url URL to which we send the request
405+
* @return mixed
388406
*/
389407
public function delete($url)
390408
{
@@ -400,8 +418,8 @@ public function delete($url)
400418
/**
401419
* Method that appears unused, but is in fact called by curl
402420
*
403-
* @param $curl
404-
* @param $body
421+
* @param resource $curl
422+
* @param string $body
405423
* @return int
406424
*/
407425
private function parseBody($curl, $body)
@@ -413,8 +431,8 @@ private function parseBody($curl, $body)
413431
/**
414432
* Method that appears unused, but is in fact called by curl
415433
*
416-
* @param $curl
417-
* @param $headers
434+
* @param resource $curl
435+
* @param string $headers
418436
* @return int
419437
*/
420438
private function parseHeader($curl, $headers)
@@ -432,6 +450,8 @@ private function parseHeader($curl, $headers)
432450

433451
/**
434452
* Access the status code of the response.
453+
*
454+
* @return mixed
435455
*/
436456
public function getStatus()
437457
{
@@ -440,6 +460,8 @@ public function getStatus()
440460

441461
/**
442462
* Access the message string from the status line of the response.
463+
*
464+
* @return string
443465
*/
444466
public function getStatusMessage()
445467
{
@@ -448,6 +470,8 @@ public function getStatusMessage()
448470

449471
/**
450472
* Access the content body of the response
473+
*
474+
* @return string
451475
*/
452476
public function getBody()
453477
{
@@ -456,6 +480,8 @@ public function getBody()
456480

457481
/**
458482
* Access given header from the response.
483+
*
484+
* @return string|void
459485
*/
460486
public function getHeader($header)
461487
{

src/Bigcommerce/Api/NetworkError.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77
*/
88
class NetworkError extends Error
99
{
10-
11-
}
10+
}

src/Bigcommerce/Api/Resource.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
class Resource
66
{
77
/**
8-
*
9-
* @var stdclass
8+
* @var \stdClass
109
*/
1110
protected $fields;
1211

@@ -72,7 +71,7 @@ public function getCreateFields()
7271
$resource = $this->fields;
7372

7473
foreach ($this->ignoreOnCreate as $field) {
75-
if (isset($resource->$field)) unset($resource->$field);
74+
unset($resource->$field);
7675
}
7776

7877
return $resource;
@@ -83,23 +82,31 @@ public function getUpdateFields()
8382
$resource = $this->fields;
8483

8584
foreach ($this->ignoreOnUpdate as $field) {
86-
if (isset($resource->$field)) unset($resource->$field);
85+
unset($resource->$field);
8786
}
8887

8988
foreach ($resource as $field => $value) {
90-
if ($this->isIgnoredField($field, $value)) unset($resource->$field);
89+
if ($this->isIgnoredField($field, $value)) {
90+
unset($resource->$field);
91+
}
9192
}
9293

9394
return $resource;
9495
}
9596

9697
private function isIgnoredField($field, $value)
9798
{
98-
if ($value === null) return true;
99+
if ($value === null) {
100+
return true;
101+
}
99102

100-
if ((strpos($field, "date") !== FALSE) && $value === "") return true;
103+
if (strpos($field, "date") !== false && $value === "") {
104+
return true;
105+
}
101106

102-
if (in_array($field, $this->ignoreIfZero) && $value === 0) return true;
107+
if (in_array($field, $this->ignoreIfZero, true) && $value === 0) {
108+
return true;
109+
}
103110

104111
return false;
105112
}

src/Bigcommerce/Api/ServerError.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77
*/
88
class ServerError extends Error
99
{
10-
11-
}
10+
}

0 commit comments

Comments
 (0)