@@ -33,7 +33,7 @@ |
||
33 | 33 | */ |
34 | 34 | protected function getRelationshipKeys(ResourceInterface $resource): array |
35 | 35 | { |
36 | - $keys = []; |
|
36 | + $keys = [ ]; |
|
37 | 37 | foreach ($resource->getRelationships() as $key => $relationships) { |
38 | 38 | if (!empty($relationships)) { |
39 | 39 | array_push($keys, ...$relationships); |
@@ -35,8 +35,8 @@ |
||
35 | 35 | */ |
36 | 36 | public function register() |
37 | 37 | { |
38 | - $this->app->singleton(Smokescreen::class, function () { |
|
39 | - return new Smokescreen(new \Rexlabs\Smokescreen\Smokescreen(), config('smokescreen', [])); |
|
38 | + $this->app->singleton(Smokescreen::class, function() { |
|
39 | + return new Smokescreen(new \Rexlabs\Smokescreen\Smokescreen(), config('smokescreen', [ ])); |
|
40 | 40 | }); |
41 | 41 | $this->app->alias(Smokescreen::class, 'smokescreen'); |
42 | 42 |
@@ -91,9 +91,9 @@ |
||
91 | 91 | $modelClass = null; |
92 | 92 | |
93 | 93 | // If not name-spaced, get a list of classes to search in common model namespaces. |
94 | - $search = strpos($name, '\\') !== false ? [$name] : array_map(function ($directory) use ($name) { |
|
94 | + $search = strpos($name, '\\') !== false ? [ $name ] : array_map(function($directory) use ($name) { |
|
95 | 95 | return $directory . '\\' . $name; |
96 | - }, ['App\\Models', 'App\\Model', 'App']); |
|
96 | + }, [ 'App\\Models', 'App\\Model', 'App' ]); |
|
97 | 97 | |
98 | 98 | // Check for a valid class. |
99 | 99 | foreach ($search as $class) { |
@@ -66,15 +66,15 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function getIncludes(): array |
68 | 68 | { |
69 | - $includes = []; |
|
69 | + $includes = [ ]; |
|
70 | 70 | collect((new ReflectionClass($this->getModel()))->getMethods(ReflectionMethod::IS_PUBLIC)) |
71 | - ->filter(function (ReflectionMethod $method) { |
|
71 | + ->filter(function(ReflectionMethod $method) { |
|
72 | 72 | // We're not interested in inherited methods |
73 | 73 | return $method->getDeclaringClass()->getName() === $this->getModelClass(); |
74 | - })->each(function (ReflectionMethod $method) use (&$includes) { |
|
74 | + })->each(function(ReflectionMethod $method) use (&$includes) { |
|
75 | 75 | // Only include if we can resolve a resource type |
76 | 76 | if (($type = $this->getResourceType($method)) !== null) { |
77 | - $includes[$method->getName()] = "relation|{$type}"; |
|
77 | + $includes[ $method->getName() ] = "relation|{$type}"; |
|
78 | 78 | } |
79 | 79 | }); |
80 | 80 | |
@@ -88,11 +88,11 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function getDeclaredProperties(): array |
90 | 90 | { |
91 | - $props = []; |
|
91 | + $props = [ ]; |
|
92 | 92 | $table = $this->getModel()->getTable(); |
93 | 93 | foreach (Schema::getColumnListing($table) as $column) { |
94 | 94 | $type = Schema::getColumnType($table, $column); |
95 | - $props[$column] = $this->schemaTypesMap[$type] ?? null; |
|
95 | + $props[ $column ] = $this->schemaTypesMap[ $type ] ?? null; |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | return $props; |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | public function getDefaultProperties(): array |
107 | 107 | { |
108 | - return []; |
|
108 | + return [ ]; |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | */ |
164 | 164 | protected function getResourceTypeByReturnType(ReflectionMethod $method) |
165 | 165 | { |
166 | - $returnType = (string)$method->getReturnType(); |
|
166 | + $returnType = (string) $method->getReturnType(); |
|
167 | 167 | $namespace = 'Illuminate\Database\Eloquent\Relations'; |
168 | 168 | |
169 | 169 | if (!starts_with($returnType, $namespace)) { |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | // $relation = lcfirst(class_basename($returnType)); |
174 | 174 | $relation = class_basename($returnType); |
175 | 175 | |
176 | - return $this->relationsMap[$relation] ?? null; |
|
176 | + return $this->relationsMap[ $relation ] ?? null; |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
@@ -189,12 +189,12 @@ discard block |
||
189 | 189 | list($statement, $returnTypes) = $match; |
190 | 190 | |
191 | 191 | // Build a regex suitable for matching our relationship keys. EG. hasOne|hasMany... |
192 | - $keyPattern = implode('|', array_map(function ($key) { |
|
192 | + $keyPattern = implode('|', array_map(function($key) { |
|
193 | 193 | return preg_quote($key, '/'); |
194 | 194 | }, array_keys($this->relationsMap))); |
195 | 195 | foreach (explode('|', $returnTypes) as $returnType) { |
196 | 196 | if (preg_match("/($keyPattern)\$/i", $returnType, $match)) { |
197 | - return $this->relationsMap[ $match[1] ] ?? null; |
|
197 | + return $this->relationsMap[ $match[ 1 ] ] ?? null; |
|
198 | 198 | } |
199 | 199 | } |
200 | 200 | } |
@@ -217,11 +217,11 @@ discard block |
||
217 | 217 | $numLines = $method->getEndLine() - $startLine; |
218 | 218 | $body = implode('', \array_slice(file($method->getFileName()), $startLine, $numLines)); |
219 | 219 | if (preg_match('/^\s*return\s+(.+?);/ms', $body, $match)) { |
220 | - $returnStmt = $match[1]; |
|
220 | + $returnStmt = $match[ 1 ]; |
|
221 | 221 | foreach (array_keys($this->relationsMap) as $returnType) { |
222 | 222 | // Find "->hasMany(" etc. |
223 | 223 | if (preg_match('/->' . preg_quote($returnType, '/') . '\(/i', $returnStmt)) { |
224 | - return $this->relationsMap[$returnType]; |
|
224 | + return $this->relationsMap[ $returnType ]; |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @param \Rexlabs\Smokescreen\Smokescreen $smokescreen |
78 | 78 | * @param array $config |
79 | 79 | */ |
80 | - public function __construct(\Rexlabs\Smokescreen\Smokescreen $smokescreen, array $config = []) |
|
80 | + public function __construct(\Rexlabs\Smokescreen\Smokescreen $smokescreen, array $config = [ ]) |
|
81 | 81 | { |
82 | 82 | $this->smokescreen = $smokescreen; |
83 | 83 | $this->setConfig($config); |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * |
92 | 92 | * @return static |
93 | 93 | */ |
94 | - public static function make(\Rexlabs\Smokescreen\Smokescreen $smokescreen = null, array $config = []) |
|
94 | + public static function make(\Rexlabs\Smokescreen\Smokescreen $smokescreen = null, array $config = [ ]) |
|
95 | 95 | { |
96 | 96 | return new static($smokescreen ?? new \Rexlabs\Smokescreen\Smokescreen(), $config); |
97 | 97 | } |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | } elseif ($data instanceof Builder) { |
229 | 229 | $data = $data->get(); |
230 | 230 | } elseif ($data instanceof Model) { |
231 | - $data = new Collection([$data]); |
|
231 | + $data = new Collection([ $data ]); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | // Create a new collection resource |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | */ |
367 | 367 | public function inject($key, $data) |
368 | 368 | { |
369 | - $this->injections[$key] = $data; |
|
369 | + $this->injections[ $key ] = $data; |
|
370 | 370 | |
371 | 371 | return $this; |
372 | 372 | } |
@@ -417,8 +417,8 @@ discard block |
||
417 | 417 | if ($this->smokescreen->getTransformerResolver() === null) { |
418 | 418 | $this->smokescreen->setTransformerResolver( |
419 | 419 | new TransformerResolver( |
420 | - $this->config['transformer_namespace'] ?? 'App\\Transformers', |
|
421 | - $this->config['transformer_name'] ?? '{ModelName}Transformer' |
|
420 | + $this->config[ 'transformer_namespace' ] ?? 'App\\Transformers', |
|
421 | + $this->config[ 'transformer_name' ] ?? '{ModelName}Transformer' |
|
422 | 422 | ) |
423 | 423 | ); |
424 | 424 | } |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | return $this->autoParseIncludes; |
472 | 472 | } |
473 | 473 | |
474 | - return $this->config['include_key'] ?? 'include'; |
|
474 | + return $this->config[ 'include_key' ] ?? 'include'; |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | * |
512 | 512 | * @see Smokescreen::toArray() |
513 | 513 | */ |
514 | - public function response(int $statusCode = 200, array $headers = [], int $options = 0): JsonResponse |
|
514 | + public function response(int $statusCode = 200, array $headers = [ ], int $options = 0): JsonResponse |
|
515 | 515 | { |
516 | 516 | // Response will only be generated once. use clearResponse() to clear. |
517 | 517 | if ($this->response === null) { |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | * @see Smokescreen::toArray() |
540 | 540 | * @see Smokescreen::response() |
541 | 541 | */ |
542 | - public function freshResponse(int $statusCode = 200, array $headers = [], int $options = 0): JsonResponse |
|
542 | + public function freshResponse(int $statusCode = 200, array $headers = [ ], int $options = 0): JsonResponse |
|
543 | 543 | { |
544 | 544 | $this->clearResponse(); |
545 | 545 | |
@@ -656,15 +656,15 @@ discard block |
||
656 | 656 | */ |
657 | 657 | protected function setConfig(array $config) |
658 | 658 | { |
659 | - if (!empty($config['default_serializer'])) { |
|
660 | - $serializer = $config['default_serializer']; |
|
659 | + if (!empty($config[ 'default_serializer' ])) { |
|
660 | + $serializer = $config[ 'default_serializer' ]; |
|
661 | 661 | if (\is_string($serializer)) { |
662 | 662 | // Given serializer is expected to be a class path |
663 | 663 | // Instantiate via the container |
664 | 664 | $serializer = app()->make($serializer); |
665 | 665 | } |
666 | 666 | $this->serializeWith($serializer); |
667 | - unset($config['default_serializer']); |
|
667 | + unset($config[ 'default_serializer' ]); |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | $this->config = $config; |