@@ -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); |
@@ -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 | } |
@@ -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 | $collection->addResource(new $resourceClass($resource)); |
91 | 91 | } catch (\Exception $e) |
92 | 92 | { |
@@ -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 |
@@ -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 $attribute; |
128 | 128 | //return $this->castAttribute($attributeKey, $attribute); |
@@ -186,11 +186,11 @@ discard block |
||
186 | 186 | */ |
187 | 187 | private function castAttribute($attributeKey, $attributeValue) |
188 | 188 | { |
189 | - if(($castTo = $this->getAttributeCastSetting($attributeKey)) !== false) |
|
189 | + if (($castTo = $this->getAttributeCastSetting($attributeKey)) !== false) |
|
190 | 190 | { |
191 | 191 | # Cast is one of date, properName etc |
192 | 192 | return $this->castAttributeFromCode($castTo, $attributeValue); |
193 | - } elseif(($castToSettings = $this->getAttributeCustomCastSettings($attributeKey)) !== false) |
|
193 | + } elseif (($castToSettings = $this->getAttributeCustomCastSettings($attributeKey)) !== false) |
|
194 | 194 | { |
195 | 195 | # Cast is custom |
196 | 196 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | // The attribute to be set in the new handler |
202 | 202 | $newHandlerAttribute = $castToSettings['new_handler_attribute']; |
203 | 203 | |
204 | - if(!$this->doesAttributeExist($newAttribute)) |
|
204 | + if (!$this->doesAttributeExist($newAttribute)) |
|
205 | 205 | { |
206 | 206 | $this->$newAttribute = new $handler([]); |
207 | 207 | } |
@@ -254,9 +254,9 @@ discard block |
||
254 | 254 | |
255 | 255 | private function getAttributeCastSetting($attributeKey) |
256 | 256 | { |
257 | - if(property_exists($this, 'casts')) |
|
257 | + if (property_exists($this, 'casts')) |
|
258 | 258 | { |
259 | - if(array_key_exists($camelCase = $this->fromSnakeToCamel($attributeKey), $this->casts)) |
|
259 | + if (array_key_exists($camelCase = $this->fromSnakeToCamel($attributeKey), $this->casts)) |
|
260 | 260 | { |
261 | 261 | return $this->casts[$camelCase]; |
262 | 262 | } |
@@ -279,11 +279,11 @@ discard block |
||
279 | 279 | */ |
280 | 280 | private function getAttributeCustomCastSettings($attributeKey) |
281 | 281 | { |
282 | - if(property_exists($this, 'customCasts') && is_array($this->customCasts)) |
|
282 | + if (property_exists($this, 'customCasts') && is_array($this->customCasts)) |
|
283 | 283 | { |
284 | - foreach($this->customCasts as $classSettings=>$customCast) |
|
284 | + foreach ($this->customCasts as $classSettings=>$customCast) |
|
285 | 285 | { |
286 | - if(array_key_exists($camelCase = $this->fromSnakeToCamel($attributeKey), $customCast)) |
|
286 | + if (array_key_exists($camelCase = $this->fromSnakeToCamel($attributeKey), $customCast)) |
|
287 | 287 | { |
288 | 288 | $castSettings = explode('|', $classSettings); |
289 | 289 | return [ |
@@ -329,9 +329,9 @@ discard block |
||
329 | 329 | * |
330 | 330 | * @return bool |
331 | 331 | */ |
332 | - private function doesAttributeExist($attributeKey, $type='camel') |
|
332 | + private function doesAttributeExist($attributeKey, $type = 'camel') |
|
333 | 333 | { |
334 | - if($type === 'camel') |
|
334 | + if ($type === 'camel') |
|
335 | 335 | { |
336 | 336 | $attributeKey = $this->fromCamelToSnake($attributeKey); |
337 | 337 | } |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | { |
340 | 340 | if (array_key_exists($attributeKey, $this->attributes)) { |
341 | 341 | // TODO Check the attribute key isn't blank |
342 | - if($this->attributes[$attributeKey]) |
|
342 | + if ($this->attributes[$attributeKey]) |
|
343 | 343 | { |
344 | 344 | return true; |
345 | 345 | } |
@@ -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(); |
@@ -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 | } |
@@ -23,7 +23,7 @@ |
||
23 | 23 | * @param int $unionCloudCode |
24 | 24 | * @param string $unionCloudMessage |
25 | 25 | */ |
26 | - public function __construct($message='Your response handler must inherit IResponse', $code=500, Throwable $previous = null, $unionCloudCode = 0, $unionCloudMessage='') |
|
26 | + public function __construct($message = 'Your response handler must inherit IResponse', $code = 500, Throwable $previous = null, $unionCloudCode = 0, $unionCloudMessage = '') |
|
27 | 27 | { |
28 | 28 | parent::__construct($message, $code, $previous, $unionCloudCode, $unionCloudMessage); |
29 | 29 | } |