@@ -28,22 +28,22 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function parse($data): Error |
30 | 30 | { |
31 | - if (! is_object($data)) { |
|
31 | + if (!is_object($data)) { |
|
32 | 32 | throw new ValidationException(sprintf('Error MUST be an object, "%s" given.', gettype($data))); |
33 | 33 | } |
34 | - if (property_exists($data, 'id') && ! is_string($data->id)) { |
|
34 | + if (property_exists($data, 'id') && !is_string($data->id)) { |
|
35 | 35 | throw new ValidationException(sprintf('Error property "id" MUST be a string, "%s" given.', gettype($data->id))); |
36 | 36 | } |
37 | - if (property_exists($data, 'status') && ! is_string($data->status)) { |
|
37 | + if (property_exists($data, 'status') && !is_string($data->status)) { |
|
38 | 38 | throw new ValidationException(sprintf('Error property "status" MUST be a string, "%s" given.', gettype($data->status))); |
39 | 39 | } |
40 | - if (property_exists($data, 'code') && ! is_string($data->code)) { |
|
40 | + if (property_exists($data, 'code') && !is_string($data->code)) { |
|
41 | 41 | throw new ValidationException(sprintf('Error property "code" MUST be a string, "%s" given.', gettype($data->code))); |
42 | 42 | } |
43 | - if (property_exists($data, 'title') && ! is_string($data->title)) { |
|
43 | + if (property_exists($data, 'title') && !is_string($data->title)) { |
|
44 | 44 | throw new ValidationException(sprintf('Error property "title" MUST be a string, "%s" given.', gettype($data->title))); |
45 | 45 | } |
46 | - if (property_exists($data, 'detail') && ! is_string($data->detail)) { |
|
46 | + if (property_exists($data, 'detail') && !is_string($data->detail)) { |
|
47 | 47 | throw new ValidationException(sprintf('Error property "detail" MUST be a string, "%s" given.', gettype($data->detail))); |
48 | 48 | } |
49 | 49 | |
@@ -64,13 +64,13 @@ discard block |
||
64 | 64 | */ |
65 | 65 | private function buildErrorSource($data): ErrorSource |
66 | 66 | { |
67 | - if (! is_object($data)) { |
|
67 | + if (!is_object($data)) { |
|
68 | 68 | throw new ValidationException(sprintf('ErrorSource MUST be an object, "%s" given.', gettype($data))); |
69 | 69 | } |
70 | - if (property_exists($data, 'pointer') && ! is_string($data->pointer)) { |
|
70 | + if (property_exists($data, 'pointer') && !is_string($data->pointer)) { |
|
71 | 71 | throw new ValidationException(sprintf('ErrorSource property "pointer" MUST be a string, "%s" given.', gettype($data->pointer))); |
72 | 72 | } |
73 | - if (property_exists($data, 'parameter') && ! is_string($data->parameter)) { |
|
73 | + if (property_exists($data, 'parameter') && !is_string($data->parameter)) { |
|
74 | 74 | throw new ValidationException(sprintf('ErrorSource property "parameter" MUST be a string, "%s" given.', gettype($data->parameter))); |
75 | 75 | } |
76 | 76 |
@@ -34,23 +34,23 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function parse($data): ItemInterface |
36 | 36 | { |
37 | - if (! is_object($data)) { |
|
37 | + if (!is_object($data)) { |
|
38 | 38 | throw new ValidationException(sprintf('Resource MUST be an object, "%s" given.', gettype($data))); |
39 | 39 | } |
40 | - if (! property_exists($data, 'type')) { |
|
40 | + if (!property_exists($data, 'type')) { |
|
41 | 41 | throw new ValidationException('Resource object MUST contain a type.'); |
42 | 42 | } |
43 | - if (! property_exists($data, 'id')) { |
|
43 | + if (!property_exists($data, 'id')) { |
|
44 | 44 | throw new ValidationException('Resource object MUST contain an id.'); |
45 | 45 | } |
46 | - if (! is_string($data->type)) { |
|
46 | + if (!is_string($data->type)) { |
|
47 | 47 | throw new ValidationException(sprintf('Resource property "type" MUST be a string, "%s" given.', gettype($data->type))); |
48 | 48 | } |
49 | - if (! is_string($data->id) && ! is_numeric($data->id)) { |
|
49 | + if (!is_string($data->id) && !is_numeric($data->id)) { |
|
50 | 50 | throw new ValidationException(sprintf('Resource property "id" MUST be a string, "%s" given.', gettype($data->id))); |
51 | 51 | } |
52 | 52 | if (property_exists($data, 'attributes')) { |
53 | - if (! is_object($data->attributes)) { |
|
53 | + if (!is_object($data->attributes)) { |
|
54 | 54 | throw new ValidationException(sprintf('Resource property "attributes" MUST be an object, "%s" given.', gettype($data->attributes))); |
55 | 55 | } |
56 | 56 | if (property_exists($data->attributes, 'type') || property_exists($data->attributes, 'id') || property_exists($data->attributes, 'relationships') || property_exists($data->attributes, 'links')) { |
@@ -59,10 +59,10 @@ discard block |
||
59 | 59 | } |
60 | 60 | |
61 | 61 | $item = $this->getItemInstance($data->type); |
62 | - $item->setId((string) $data->id); |
|
62 | + $item->setId((string)$data->id); |
|
63 | 63 | |
64 | 64 | if (property_exists($data, 'attributes')) { |
65 | - $item->fill((array) $data->attributes); |
|
65 | + $item->fill((array)$data->attributes); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | if (property_exists($data, 'relationships')) { |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | */ |
95 | 95 | private function setRelations(ItemInterface $item, $data): void |
96 | 96 | { |
97 | - if (! is_object($data)) { |
|
97 | + if (!is_object($data)) { |
|
98 | 98 | throw new ValidationException(sprintf('Resource property "relationships" MUST be an object, "%s" given.', gettype($data))); |
99 | 99 | } |
100 | 100 | if (property_exists($data, 'type') || property_exists($data, 'id')) { |
@@ -105,10 +105,10 @@ discard block |
||
105 | 105 | if ($item->hasAttribute($name)) { |
106 | 106 | throw new ValidationException(sprintf('Relationship "%s" cannot be set because it already exists in Resource object.', $name)); |
107 | 107 | } |
108 | - if (! is_object($relationship)) { |
|
108 | + if (!is_object($relationship)) { |
|
109 | 109 | throw new ValidationException(sprintf('Relationship MUST be an object, "%s" given.', gettype($relationship))); |
110 | 110 | } |
111 | - if (! property_exists($relationship, 'links') && ! property_exists($relationship, 'data') && ! property_exists($relationship, 'meta')) { |
|
111 | + if (!property_exists($relationship, 'links') && !property_exists($relationship, 'data') && !property_exists($relationship, 'meta')) { |
|
112 | 112 | throw new ValidationException('Relationship object MUST contain at least one of the following properties: `links`, `data`, `meta`.'); |
113 | 113 | } |
114 | 114 | |
@@ -146,23 +146,23 @@ discard block |
||
146 | 146 | ->map(fn ($identifier) => $this->parseRelationshipData($identifier)); |
147 | 147 | } |
148 | 148 | |
149 | - if (! is_object($data)) { |
|
149 | + if (!is_object($data)) { |
|
150 | 150 | throw new ValidationException(sprintf('ResourceIdentifier MUST be an object, "%s" given.', gettype($data))); |
151 | 151 | } |
152 | - if (! property_exists($data, 'type')) { |
|
152 | + if (!property_exists($data, 'type')) { |
|
153 | 153 | throw new ValidationException('ResourceIdentifier object MUST contain a type.'); |
154 | 154 | } |
155 | - if (! property_exists($data, 'id')) { |
|
155 | + if (!property_exists($data, 'id')) { |
|
156 | 156 | throw new ValidationException('ResourceIdentifier object MUST contain an id.'); |
157 | 157 | } |
158 | - if (! is_string($data->type)) { |
|
158 | + if (!is_string($data->type)) { |
|
159 | 159 | throw new ValidationException(sprintf('ResourceIdentifier property "type" MUST be a string, "%s" given.', gettype($data->type))); |
160 | 160 | } |
161 | - if (! is_string($data->id) && ! is_numeric($data->id)) { |
|
161 | + if (!is_string($data->id) && !is_numeric($data->id)) { |
|
162 | 162 | throw new ValidationException(sprintf('ResourceIdentifier property "id" MUST be a string, "%s" given.', gettype($data->id))); |
163 | 163 | } |
164 | 164 | |
165 | - $item = $this->getItemInstance($data->type)->setId((string) $data->id); |
|
165 | + $item = $this->getItemInstance($data->type)->setId((string)$data->id); |
|
166 | 166 | if (property_exists($data, 'meta')) { |
167 | 167 | $item->setMeta($this->metaParser->parse($data->meta)); |
168 | 168 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | $document = new InvalidResponseDocument; |
35 | 35 | |
36 | 36 | if ($this->responseHasBody($response)) { |
37 | - $document = $this->parser->parse((string) $response->getBody()); |
|
37 | + $document = $this->parser->parse((string)$response->getBody()); |
|
38 | 38 | } elseif ($this->responseHasSuccessfulStatusCode($response)) { |
39 | 39 | $document = new Document; |
40 | 40 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | |
47 | 47 | private function responseHasBody(ResponseInterface $response): bool |
48 | 48 | { |
49 | - return (bool) $response->getBody()->getSize(); |
|
49 | + return (bool)$response->getBody()->getSize(); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | private function responseHasSuccessfulStatusCode(ResponseInterface $response): bool |
@@ -20,11 +20,11 @@ discard block |
||
20 | 20 | */ |
21 | 21 | public function setMapping(string $type, string $class): void |
22 | 22 | { |
23 | - if (! class_exists($class)) { |
|
23 | + if (!class_exists($class)) { |
|
24 | 24 | throw new TypeMappingException(sprintf('Class %s not found.', $class)); |
25 | 25 | } |
26 | 26 | |
27 | - if (! is_subclass_of($class, ItemInterface::class)) { |
|
27 | + if (!is_subclass_of($class, ItemInterface::class)) { |
|
28 | 28 | throw new TypeMappingException(sprintf('Class %s must implement %s.', $class, ItemInterface::class)); |
29 | 29 | } |
30 | 30 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function getMapping(string $type): ItemInterface |
48 | 48 | { |
49 | - if (! array_key_exists($type, $this->typeMappings)) { |
|
49 | + if (!array_key_exists($type, $this->typeMappings)) { |
|
50 | 50 | throw new TypeMappingException(sprintf('No mapping for type %s', $type)); |
51 | 51 | } |
52 | 52 |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | { |
57 | 57 | // Fill Relations |
58 | 58 | foreach ($item->getAvailableRelations() as $availableRelation) { |
59 | - if (! array_key_exists($availableRelation, $attributes)) { |
|
59 | + if (!array_key_exists($availableRelation, $attributes)) { |
|
60 | 60 | // No data found, continue |
61 | 61 | continue; |
62 | 62 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | protected function getRelationFromItem(ItemInterface $item, string $availableRelation) |
95 | 95 | { |
96 | 96 | $method = Util::stringCamel($availableRelation); |
97 | - if (! method_exists($item, $method)) { |
|
97 | + if (!method_exists($item, $method)) { |
|
98 | 98 | throw new HydrationException(sprintf('Method %s not found on %s', $method, get_class($item))); |
99 | 99 | } |
100 | 100 | |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | */ |
139 | 139 | protected function hydrateMorphToRelation(MorphToRelation $relation, array $attributes): void |
140 | 140 | { |
141 | - if (! array_key_exists('type', $attributes)) { |
|
141 | + if (!array_key_exists('type', $attributes)) { |
|
142 | 142 | throw new HydrationException('Always provide a "type" attribute in a morphTo relationship'); |
143 | 143 | } |
144 | 144 | $relationItem = $this->buildItem($attributes['type'], Util::arrayExcept($attributes, 'type')); |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | protected function hydrateMorphToManyRelation(MorphToManyRelation $relation, array $attributes): void |
153 | 153 | { |
154 | 154 | foreach ($attributes as $relationData) { |
155 | - if (! array_key_exists('type', $relationData)) { |
|
155 | + if (!array_key_exists('type', $relationData)) { |
|
156 | 156 | throw new HydrationException('Always provide a "type" attribute in a morphToMany relationship entry'); |
157 | 157 | } |
158 | 158 | $relationItem = $this->buildItem($relationData['type'], Util::arrayExcept($relationData, 'type')); |
@@ -171,6 +171,6 @@ discard block |
||
171 | 171 | $item = $this->typeMapper->getMapping($type); |
172 | 172 | } |
173 | 173 | |
174 | - return $this->hydrate($item, $attributes, (string) $attributes['id']); |
|
174 | + return $this->hydrate($item, $attributes, (string)$attributes['id']); |
|
175 | 175 | } |
176 | 176 | } |
@@ -123,12 +123,12 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | $attributes = $this->toArray(); |
126 | - if (! empty($attributes)) { |
|
126 | + if (!empty($attributes)) { |
|
127 | 127 | $data['attributes'] = $attributes; |
128 | 128 | } |
129 | 129 | |
130 | 130 | $relationships = $this->getRelationships(); |
131 | - if (! empty($relationships)) { |
|
131 | + if (!empty($relationships)) { |
|
132 | 132 | $data['relationships'] = $relationships; |
133 | 133 | } |
134 | 134 | |
@@ -192,12 +192,12 @@ discard block |
||
192 | 192 | |
193 | 193 | public function isNew(): bool |
194 | 194 | { |
195 | - return ! $this->hasId(); |
|
195 | + return !$this->hasId(); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | public function hasAttributes(): bool |
199 | 199 | { |
200 | - return ! empty($this->toArray()); |
|
200 | + return !empty($this->toArray()); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | $relationships = []; |
219 | 219 | |
220 | 220 | foreach ($this->getRelations() as $name => $relation) { |
221 | - if (! $relation->hasAssociated()) { |
|
221 | + if (!$relation->hasAssociated()) { |
|
222 | 222 | continue; |
223 | 223 | } |
224 | 224 | |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | |
266 | 266 | public function hasRelationships(): bool |
267 | 267 | { |
268 | - return ! empty($this->getRelationships()); |
|
268 | + return !empty($this->getRelationships()); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | return $this->hasId(); |
316 | 316 | } |
317 | 317 | |
318 | - return ! is_null($this->getAttribute($offset)); |
|
318 | + return !is_null($this->getAttribute($offset)); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | public function offsetSet($offset, $value) |
346 | 346 | { |
347 | 347 | if ($offset === 'id') { |
348 | - $this->setId($value ? (string) $value : null); |
|
348 | + $this->setId($value ? (string)$value : null); |
|
349 | 349 | |
350 | 350 | return; |
351 | 351 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | { |
34 | 34 | $name = $name ?: $this->guessRelationName(); |
35 | 35 | |
36 | - if (! array_key_exists($name, $this->relations)) { |
|
36 | + if (!array_key_exists($name, $this->relations)) { |
|
37 | 37 | $this->relations[$name] = $this->newHasOne((new $itemClass)->getType()); |
38 | 38 | } |
39 | 39 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | { |
56 | 56 | $name = $name ?: $this->guessRelationName(); |
57 | 57 | |
58 | - if (! array_key_exists($name, $this->relations)) { |
|
58 | + if (!array_key_exists($name, $this->relations)) { |
|
59 | 59 | $this->relations[$name] = $this->newHasMany((new $itemClass)->getType()); |
60 | 60 | } |
61 | 61 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | { |
78 | 78 | $name = $name ?: $this->guessRelationName(); |
79 | 79 | |
80 | - if (! array_key_exists($name, $this->relations)) { |
|
80 | + if (!array_key_exists($name, $this->relations)) { |
|
81 | 81 | $this->relations[$name] = $this->newMorphTo(); |
82 | 82 | } |
83 | 83 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | { |
100 | 100 | $name = $name ?: $this->guessRelationName(); |
101 | 101 | |
102 | - if (! array_key_exists($name, $this->relations)) { |
|
102 | + if (!array_key_exists($name, $this->relations)) { |
|
103 | 103 | $this->relations[$name] = $this->newMorphToMany(); |
104 | 104 | } |
105 | 105 |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | // We want to spin through all the mutated attributes for this model and call |
108 | 108 | // the mutator for the attribute. We cache off every mutated attributes so |
109 | 109 | // we don't have to constantly check on attributes that actually change. |
110 | - if (! array_key_exists($key, $attributes)) { |
|
110 | + if (!array_key_exists($key, $attributes)) { |
|
111 | 111 | continue; |
112 | 112 | } |
113 | 113 | |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | protected function addCastAttributesToArray(array $attributes, array $mutatedAttributes) |
132 | 132 | { |
133 | 133 | foreach ($this->getCasts() as $key => $value) { |
134 | - if (! array_key_exists($key, $attributes) |
|
134 | + if (!array_key_exists($key, $attributes) |
|
135 | 135 | || in_array($key, $mutatedAttributes)) { |
136 | 136 | continue; |
137 | 137 | } |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | */ |
169 | 169 | protected function getArrayableAppends() |
170 | 170 | { |
171 | - if (! count($this->appends)) { |
|
171 | + if (!count($this->appends)) { |
|
172 | 172 | return []; |
173 | 173 | } |
174 | 174 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | */ |
205 | 205 | public function getAttribute($key) |
206 | 206 | { |
207 | - if (! $key) { |
|
207 | + if (!$key) { |
|
208 | 208 | return; |
209 | 209 | } |
210 | 210 | |
@@ -315,16 +315,16 @@ discard block |
||
315 | 315 | switch ($this->getCastType($key)) { |
316 | 316 | case 'int': |
317 | 317 | case 'integer': |
318 | - return (int) $value; |
|
318 | + return (int)$value; |
|
319 | 319 | case 'real': |
320 | 320 | case 'float': |
321 | 321 | case 'double': |
322 | 322 | return $this->fromFloat($value); |
323 | 323 | case 'string': |
324 | - return (string) $value; |
|
324 | + return (string)$value; |
|
325 | 325 | case 'bool': |
326 | 326 | case 'boolean': |
327 | - return (bool) $value; |
|
327 | + return (bool)$value; |
|
328 | 328 | case 'object': |
329 | 329 | return $this->fromJson($value, true); |
330 | 330 | case 'array': |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | return $this->setMutatedAttributeValue($key, $value); |
365 | 365 | } |
366 | 366 | |
367 | - if (! is_null($value) && $this->isJsonCastable($key)) { |
|
367 | + if (!is_null($value) && $this->isJsonCastable($key)) { |
|
368 | 368 | $value = $this->asJson($value); |
369 | 369 | } |
370 | 370 | |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | */ |
416 | 416 | public function fromJson(string $value, $asObject = false) |
417 | 417 | { |
418 | - return json_decode($value, ! $asObject, 512, JSON_THROW_ON_ERROR); |
|
418 | + return json_decode($value, !$asObject, 512, JSON_THROW_ON_ERROR); |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | /** |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | */ |
427 | 427 | public function fromFloat($value) |
428 | 428 | { |
429 | - switch ((string) $value) { |
|
429 | + switch ((string)$value) { |
|
430 | 430 | case 'Infinity': |
431 | 431 | return INF; |
432 | 432 | case '-Infinity': |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | case 'NaN': |
435 | 435 | return NAN; |
436 | 436 | default: |
437 | - return (float) $value; |
|
437 | + return (float)$value; |
|
438 | 438 | } |
439 | 439 | } |
440 | 440 | |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | public function hasCast($key, $types = null) |
449 | 449 | { |
450 | 450 | if (array_key_exists($key, $this->getCasts())) { |
451 | - return $types ? in_array($this->getCastType($key), (array) $types, true) : true; |
|
451 | + return $types ? in_array($this->getCastType($key), (array)$types, true) : true; |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | return false; |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | { |
575 | 575 | $class = static::class; |
576 | 576 | |
577 | - if (! isset(static::$mutatorCache[$class])) { |
|
577 | + if (!isset(static::$mutatorCache[$class])) { |
|
578 | 578 | static::cacheMutatedAttributes($class); |
579 | 579 | } |
580 | 580 |
@@ -40,7 +40,7 @@ |
||
40 | 40 | public function hasInitial($key = null): bool |
41 | 41 | { |
42 | 42 | if ($key === null) { |
43 | - return ! empty($this->initial); |
|
43 | + return !empty($this->initial); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | return isset($this->initial[$key]); |