@@ -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; |
@@ -16,14 +16,14 @@ discard block |
||
16 | 16 | public function boot() |
17 | 17 | { |
18 | 18 | $this->publishes([ |
19 | - __DIR__.'/../../config/smokescreen.php' => config_path('smokescreen.php'), |
|
19 | + __DIR__ . '/../../config/smokescreen.php' => config_path('smokescreen.php'), |
|
20 | 20 | ], 'config'); |
21 | 21 | |
22 | 22 | $this->publishes([ |
23 | - __DIR__.'/../../stubs' => resource_path('views/vendor/smokescreen'), |
|
23 | + __DIR__ . '/../../stubs' => resource_path('views/vendor/smokescreen'), |
|
24 | 24 | ], 'stub'); |
25 | 25 | |
26 | - $this->loadViewsFrom(__DIR__.'/../../stubs', 'smokescreen'); |
|
26 | + $this->loadViewsFrom(__DIR__ . '/../../stubs', 'smokescreen'); |
|
27 | 27 | |
28 | 28 | $this->commands(MakeTransformerCommand::class); |
29 | 29 | } |
@@ -35,13 +35,13 @@ discard block |
||
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 | |
43 | 43 | $this->mergeConfigFrom( |
44 | - __DIR__.'/../../config/smokescreen.php', |
|
44 | + __DIR__ . '/../../config/smokescreen.php', |
|
45 | 45 | 'smokescreen' |
46 | 46 | ); |
47 | 47 | } |
@@ -58,7 +58,7 @@ |
||
58 | 58 | $transformerName = preg_replace('/{ModelName}/i', $modelName, $this->nameTemplate); |
59 | 59 | $transformer = resolve(sprintf('%s\\%s', $this->namespace, $transformerName)); |
60 | 60 | } catch (\Exception $e) { |
61 | - throw new UnresolvedTransformerException('Unable to resolve transformer for model: '.\get_class($model), |
|
61 | + throw new UnresolvedTransformerException('Unable to resolve transformer for model: ' . \get_class($model), |
|
62 | 62 | 0, $e); |
63 | 63 | } |
64 | 64 | } |
@@ -18,13 +18,13 @@ discard block |
||
18 | 18 | */ |
19 | 19 | public function findInDirectory(string $directory): array |
20 | 20 | { |
21 | - $models = []; |
|
21 | + $models = [ ]; |
|
22 | 22 | $iterator = Finder::create()->files()->name('*.php')->in($directory)->depth(0)->sortByName(); |
23 | 23 | |
24 | 24 | foreach ($iterator as $file) { |
25 | 25 | $class = $this->determineClassFromFile($file); |
26 | 26 | if ($class !== null && class_exists($class) && $this->isModelClass($class)) { |
27 | - $models[] = $class; |
|
27 | + $models[ ] = $class; |
|
28 | 28 | } |
29 | 29 | } |
30 | 30 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | return null; |
45 | 45 | } |
46 | 46 | |
47 | - return $matches[1] . '\\' . rtrim($file->getFilename(), '.php'); |
|
47 | + return $matches[ 1 ] . '\\' . rtrim($file->getFilename(), '.php'); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -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 | /** |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | |
173 | 173 | $relation = class_basename($returnType); |
174 | 174 | |
175 | - return $this->relationsMap[$relation] ?? null; |
|
175 | + return $this->relationsMap[ $relation ] ?? null; |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -188,12 +188,12 @@ discard block |
||
188 | 188 | list($statement, $returnTypes) = $match; |
189 | 189 | |
190 | 190 | // Build a regex suitable for matching our relationship keys. EG. hasOne|hasMany... |
191 | - $keyPattern = implode('|', array_map(function ($key) { |
|
191 | + $keyPattern = implode('|', array_map(function($key) { |
|
192 | 192 | return preg_quote($key, '/'); |
193 | 193 | }, array_keys($this->relationsMap))); |
194 | 194 | foreach (explode('|', $returnTypes) as $returnType) { |
195 | 195 | if (preg_match("/($keyPattern)\$/i", $returnType, $match)) { |
196 | - return $this->relationsMap[$match[1]] ?? null; |
|
196 | + return $this->relationsMap[ $match[ 1 ] ] ?? null; |
|
197 | 197 | } |
198 | 198 | } |
199 | 199 | } |
@@ -216,11 +216,11 @@ discard block |
||
216 | 216 | $numLines = $method->getEndLine() - $startLine; |
217 | 217 | $body = implode('', \array_slice(file($method->getFileName()), $startLine, $numLines)); |
218 | 218 | if (preg_match('/^\s*return\s+(.+?);/ms', $body, $match)) { |
219 | - $returnStmt = $match[1]; |
|
219 | + $returnStmt = $match[ 1 ]; |
|
220 | 220 | foreach (array_keys($this->relationsMap) as $returnType) { |
221 | 221 | // Find "->hasMany(" etc. |
222 | - if (preg_match('/->'.preg_quote($returnType, '/').'\(/i', $returnStmt)) { |
|
223 | - return $this->relationsMap[$returnType]; |
|
222 | + if (preg_match('/->' . preg_quote($returnType, '/') . '\(/i', $returnStmt)) { |
|
223 | + return $this->relationsMap[ $returnType ]; |
|
224 | 224 | } |
225 | 225 | } |
226 | 226 | } |