@@ -28,13 +28,13 @@ |
||
28 | 28 | trait ParsesAttributes |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * Convert camelCase to snake_case |
|
33 | - * |
|
34 | - * @param string $key |
|
35 | - * |
|
36 | - * @return string |
|
37 | - */ |
|
31 | + /** |
|
32 | + * Convert camelCase to snake_case |
|
33 | + * |
|
34 | + * @param string $key |
|
35 | + * |
|
36 | + * @return string |
|
37 | + */ |
|
38 | 38 | public function fromCamelToSnake($key) |
39 | 39 | { |
40 | 40 | preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $key, $matches); |
@@ -84,9 +84,9 @@ |
||
84 | 84 | public function parseCustomResource($attributeValue, $resourceClass) |
85 | 85 | { |
86 | 86 | $collection = new ResourceCollection(); |
87 | - foreach($attributeValue as $resource) |
|
87 | + foreach ($attributeValue as $resource) |
|
88 | 88 | { |
89 | - try{ |
|
89 | + try { |
|
90 | 90 | |
91 | 91 | } catch (\Exception $e) |
92 | 92 | { |
@@ -52,17 +52,19 @@ |
||
52 | 52 | $newWords = array(); |
53 | 53 | foreach ($words as $word) |
54 | 54 | { |
55 | - if (in_array(strtoupper($word), $uppercase_exceptions)) |
|
56 | - $word = strtoupper($word); |
|
57 | - else |
|
58 | - if (!in_array($word, $lowercase_exceptions)) |
|
59 | - $word = ucfirst($word); |
|
55 | + if (in_array(strtoupper($word), $uppercase_exceptions)) { |
|
56 | + $word = strtoupper($word); |
|
57 | + } else |
|
58 | + if (!in_array($word, $lowercase_exceptions)) { |
|
59 | + $word = ucfirst($word); |
|
60 | + } |
|
60 | 61 | |
61 | 62 | $newWords[] = $word; |
62 | 63 | } |
63 | 64 | |
64 | - if (in_array(strtolower($delimiter), $lowercase_exceptions)) |
|
65 | - $delimiter = strtolower($delimiter); |
|
65 | + if (in_array(strtolower($delimiter), $lowercase_exceptions)) { |
|
66 | + $delimiter = strtolower($delimiter); |
|
67 | + } |
|
66 | 68 | |
67 | 69 | $attributeValue = join($delimiter, $newWords); |
68 | 70 | } |
@@ -97,10 +97,10 @@ discard block |
||
97 | 97 | */ |
98 | 98 | protected function setAllAttributes($attributes) |
99 | 99 | { |
100 | - foreach($attributes as $attributeKey => $value) |
|
100 | + foreach ($attributes as $attributeKey => $value) |
|
101 | 101 | { |
102 | 102 | $value = $this->castAttribute($attributeKey, $value); |
103 | - if($value !== null) // Will occur for customCasts, since we don't want the attribute to exist in this class but in the child resource |
|
103 | + if ($value !== null) // Will occur for customCasts, since we don't want the attribute to exist in this class but in the child resource |
|
104 | 104 | { |
105 | 105 | $this->attributes[$attributeKey] = $value; |
106 | 106 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function __get($attributeKey) |
124 | 124 | { |
125 | - if($this->doesAttributeExist($attributeKey)) { |
|
125 | + if ($this->doesAttributeExist($attributeKey)) { |
|
126 | 126 | $attribute = $this->attributes[$attributeKey]; |
127 | 127 | return $this->castAttribute($attributeKey, $attribute); |
128 | 128 | } |
@@ -185,10 +185,10 @@ discard block |
||
185 | 185 | */ |
186 | 186 | private function castAttribute($attributeKey, $attributeValue) |
187 | 187 | { |
188 | - if(($castTo = $this->getAttributeCastSetting($attributeKey)) !== false) |
|
188 | + if (($castTo = $this->getAttributeCastSetting($attributeKey)) !== false) |
|
189 | 189 | { |
190 | 190 | return $this->castAttributeFromCode($castTo, $attributeValue); |
191 | - } elseif(($castToSettings = $this->getAttributeCustomCastSettings($attributeKey)) !== false) |
|
191 | + } elseif (($castToSettings = $this->getAttributeCustomCastSettings($attributeKey)) !== false) |
|
192 | 192 | { |
193 | 193 | // The attribute under which the new resource is accessible |
194 | 194 | $newAttribute = $castToSettings['new_attribute']; |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | // The attribute to be set in the new handler |
200 | 200 | $newHandlerAttribute = $castToSettings['new_handler_attribute']; |
201 | 201 | |
202 | - if(!$this->doesAttributeExist($newAttribute)) |
|
202 | + if (!$this->doesAttributeExist($newAttribute)) |
|
203 | 203 | { |
204 | 204 | $this->$newAttribute = new $handler([]); |
205 | 205 | } |
@@ -252,9 +252,9 @@ discard block |
||
252 | 252 | |
253 | 253 | private function getAttributeCastSetting($attributeKey) |
254 | 254 | { |
255 | - if(property_exists($this, 'casts')) |
|
255 | + if (property_exists($this, 'casts')) |
|
256 | 256 | { |
257 | - if(array_key_exists($camelCase = $this->fromSnakeToCamel($attributeKey), $this->casts)) |
|
257 | + if (array_key_exists($camelCase = $this->fromSnakeToCamel($attributeKey), $this->casts)) |
|
258 | 258 | { |
259 | 259 | return $this->casts[$camelCase]; |
260 | 260 | } |
@@ -277,11 +277,11 @@ discard block |
||
277 | 277 | */ |
278 | 278 | private function getAttributeCustomCastSettings($attributeKey) |
279 | 279 | { |
280 | - if(property_exists($this, 'customCasts') && is_array($this->customCasts)) |
|
280 | + if (property_exists($this, 'customCasts') && is_array($this->customCasts)) |
|
281 | 281 | { |
282 | - foreach($this->customCasts as $classSettings=>$customCast) |
|
282 | + foreach ($this->customCasts as $classSettings=>$customCast) |
|
283 | 283 | { |
284 | - if(array_key_exists($camelCase = $this->fromSnakeToCamel($attributeKey), $customCast)) |
|
284 | + if (array_key_exists($camelCase = $this->fromSnakeToCamel($attributeKey), $customCast)) |
|
285 | 285 | { |
286 | 286 | $castSettings = explode('|', $classSettings); |
287 | 287 | return [ |
@@ -327,9 +327,9 @@ discard block |
||
327 | 327 | * |
328 | 328 | * @return bool |
329 | 329 | */ |
330 | - private function doesAttributeExist($attributeKey, $type='camel') |
|
330 | + private function doesAttributeExist($attributeKey, $type = 'camel') |
|
331 | 331 | { |
332 | - if($type === 'camel') |
|
332 | + if ($type === 'camel') |
|
333 | 333 | { |
334 | 334 | $attributeKey = $this->fromCamelToSnake($attributeKey); |
335 | 335 | } |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | { |
338 | 338 | if (array_key_exists($attributeKey, $this->attributes)) { |
339 | 339 | // TODO Check the attribute key isn't blank |
340 | - if($this->attributes[$attributeKey]) |
|
340 | + if ($this->attributes[$attributeKey]) |
|
341 | 341 | { |
342 | 342 | return true; |
343 | 343 | } |
@@ -100,10 +100,12 @@ |
||
100 | 100 | foreach($attributes as $attributeKey => $value) |
101 | 101 | { |
102 | 102 | $value = $this->castAttribute($attributeKey, $value); |
103 | - if($value !== null) // Will occur for customCasts, since we don't want the attribute to exist in this class but in the child resource |
|
103 | + if($value !== null) { |
|
104 | + // Will occur for customCasts, since we don't want the attribute to exist in this class but in the child resource |
|
104 | 105 | { |
105 | 106 | $this->attributes[$attributeKey] = $value; |
106 | 107 | } |
108 | + } |
|
107 | 109 | } |
108 | 110 | } |
109 | 111 |
@@ -397,13 +397,13 @@ |
||
397 | 397 | * @param string $method |
398 | 398 | * @param array|null $body If you don't include it in a data array, we will |
399 | 399 | */ |
400 | - protected function setAPIParameters($endpoint,$method,$body=null) |
|
400 | + protected function setAPIParameters($endpoint, $method, $body = null) |
|
401 | 401 | { |
402 | 402 | $this->setEndpoint($endpoint); |
403 | 403 | $this->setMethod($method); |
404 | - if($body !== null) |
|
404 | + if ($body !== null) |
|
405 | 405 | { |
406 | - $this->setBody((array_key_exists('data', $body)?$body:array('data'=>$body))); |
|
406 | + $this->setBody((array_key_exists('data', $body) ? $body : array('data'=>$body))); |
|
407 | 407 | } |
408 | 408 | } |
409 | 409 |
@@ -373,8 +373,7 @@ discard block |
||
373 | 373 | */ |
374 | 374 | protected function setContentType($contentType) |
375 | 375 | { |
376 | - if ($contentType === 'json') { $contentType = 'application/json'; } |
|
377 | - elseif ($contentType === 'form') { $contentType = 'application/x-www-form-urlencoded'; } |
|
376 | + if ($contentType === 'json') { $contentType = 'application/json'; } elseif ($contentType === 'form') { $contentType = 'application/x-www-form-urlencoded'; } |
|
378 | 377 | $this->contentType = $contentType; |
379 | 378 | } |
380 | 379 | |
@@ -551,8 +550,7 @@ discard block |
||
551 | 550 | { |
552 | 551 | if (!$this->contentType) |
553 | 552 | { |
554 | - if ($this->getMethod() === 'POST') { return 'application/x-www-form-urlencoded'; } |
|
555 | - else { return 'application/json'; } |
|
553 | + if ($this->getMethod() === 'POST') { return 'application/x-www-form-urlencoded'; } else { return 'application/json'; } |
|
556 | 554 | } |
557 | 555 | return $this->contentType; |
558 | 556 | } |
@@ -78,8 +78,8 @@ |
||
78 | 78 | 'GET' |
79 | 79 | ); |
80 | 80 | |
81 | - if($updatedAfter !== null) { $this->addQueryParameter('updated_at_after', $updatedAfter->format('d-m-y H:i:s')); } |
|
82 | - if($updatedBefore !== null) { $this->addQueryParameter('updated_at_before', $updatedBefore->format('d-m-y H:i:s')); } |
|
81 | + if ($updatedAfter !== null) { $this->addQueryParameter('updated_at_after', $updatedAfter->format('d-m-y H:i:s')); } |
|
82 | + if ($updatedBefore !== null) { $this->addQueryParameter('updated_at_before', $updatedBefore->format('d-m-y H:i:s')); } |
|
83 | 83 | |
84 | 84 | $this->enableMode(); |
85 | 85 | $this->enablePagination(); |
@@ -366,38 +366,38 @@ discard block |
||
366 | 366 | { |
367 | 367 | |
368 | 368 | // If no data was returned, no resource was found |
369 | - if($this->getRawData() === null) |
|
369 | + if ($this->getRawData() === null) |
|
370 | 370 | { |
371 | 371 | throw new ResourceNotFoundException('The resource wasn\'t found', 404); |
372 | 372 | } |
373 | 373 | |
374 | - $responseBody = (array_key_exists(0, $this->getRawData())?$this->getRawData()[0]:$this->getRawData()); |
|
374 | + $responseBody = (array_key_exists(0, $this->getRawData()) ? $this->getRawData()[0] : $this->getRawData()); |
|
375 | 375 | |
376 | 376 | // Process the standard error code response. |
377 | 377 | |
378 | - if(array_key_exists('errors', $responseBody) || array_key_exists('error', $responseBody)) |
|
378 | + if (array_key_exists('errors', $responseBody) || array_key_exists('error', $responseBody)) |
|
379 | 379 | { |
380 | 380 | $errors = []; |
381 | 381 | // Get the errors |
382 | - if(array_key_exists('errors', $responseBody)) |
|
382 | + if (array_key_exists('errors', $responseBody)) |
|
383 | 383 | { |
384 | 384 | $errors = $responseBody['errors']; |
385 | - } elseif(array_key_exists('error', $responseBody)) |
|
385 | + } elseif (array_key_exists('error', $responseBody)) |
|
386 | 386 | { |
387 | 387 | $errors = $responseBody['error']; |
388 | 388 | } |
389 | 389 | |
390 | 390 | // Standardize the errors. If the errors aren't in an enclosing array, put them in one so we can iterate through them |
391 | - if(! array_key_exists(0, $errors)) |
|
391 | + if (!array_key_exists(0, $errors)) |
|
392 | 392 | { |
393 | 393 | $errors = [$errors]; |
394 | 394 | } |
395 | 395 | |
396 | 396 | // Throw the error |
397 | 397 | // TODO allow all errors to be seen by the user |
398 | - foreach($errors as $error) |
|
398 | + foreach ($errors as $error) |
|
399 | 399 | { |
400 | - if(array_key_exists('error_code', $error) && array_key_exists('error_message', $error)) |
|
400 | + if (array_key_exists('error_code', $error) && array_key_exists('error_message', $error)) |
|
401 | 401 | { |
402 | 402 | $this->throwCustomUnionCloudError($error); |
403 | 403 | } |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | { |
425 | 425 | $errorCode = $error['error_code']; |
426 | 426 | $errorMessage = $error['error_message']; |
427 | - if(($errorDetails = $this->getUnionCloudErrorDetails($errorCode)) !== false) |
|
427 | + if (($errorDetails = $this->getUnionCloudErrorDetails($errorCode)) !== false) |
|
428 | 428 | { |
429 | 429 | throw new $errorDetails['errorClass']($errorDetails['message'], $errorDetails['code'], null, $errorCode, $errorMessage); |
430 | 430 | } |
@@ -761,7 +761,7 @@ discard block |
||
761 | 761 | ], |
762 | 762 | ]; |
763 | 763 | |
764 | - if(array_key_exists($errorCode, $errors)) |
|
764 | + if (array_key_exists($errorCode, $errors)) |
|
765 | 765 | { |
766 | 766 | $error = $errors[$errorCode]; |
767 | 767 | return [ |
@@ -790,7 +790,7 @@ discard block |
||
790 | 790 | $parsedResource = $this->parseResource($resource); |
791 | 791 | $resources->addResource($parsedResource); |
792 | 792 | } |
793 | - } catch(\Exception $e) { } |
|
793 | + } catch (\Exception $e) { } |
|
794 | 794 | return $resources; |
795 | 795 | } |
796 | 796 |
@@ -225,12 +225,12 @@ |
||
225 | 225 | */ |
226 | 226 | public function needsRefresh() |
227 | 227 | { |
228 | - if($this->expires === null) |
|
228 | + if ($this->expires === null) |
|
229 | 229 | { |
230 | 230 | return true; |
231 | 231 | } elseif ($this->expires instanceof Carbon) |
232 | 232 | { |
233 | - return ! $this->expires->isFuture(); |
|
233 | + return !$this->expires->isFuture(); |
|
234 | 234 | } |
235 | 235 | return true; |
236 | 236 | } |
@@ -24,7 +24,7 @@ |
||
24 | 24 | * @param int $unionCloudCode |
25 | 25 | * @param string $unionCloudMessage |
26 | 26 | */ |
27 | - public function __construct($message='The response from Guzzle was of an incorrect type.', $code=500, Throwable $previous = null, $unionCloudCode = 0, $unionCloudMessage='') |
|
27 | + public function __construct($message = 'The response from Guzzle was of an incorrect type.', $code = 500, Throwable $previous = null, $unionCloudCode = 0, $unionCloudMessage = '') |
|
28 | 28 | { |
29 | 29 | parent::__construct($message, $code, $previous, $unionCloudCode, $unionCloudMessage); |
30 | 30 | } |
@@ -24,7 +24,7 @@ |
||
24 | 24 | * @param int $unionCloudCode |
25 | 25 | * @param string $unionCloudMessage |
26 | 26 | */ |
27 | - public function __construct($message='A problem occured processing the response', $code=500, Throwable $previous = null, $unionCloudCode = 0, $unionCloudMessage='') |
|
27 | + public function __construct($message = 'A problem occured processing the response', $code = 500, Throwable $previous = null, $unionCloudCode = 0, $unionCloudMessage = '') |
|
28 | 28 | { |
29 | 29 | parent::__construct($message, $code, $previous, $unionCloudCode, $unionCloudMessage); |
30 | 30 | } |