@@ -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 | /** |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * @param \Rexlabs\Smokescreen\Smokescreen $smokescreen |
| 97 | 97 | * @param array $config |
| 98 | 98 | */ |
| 99 | - public function __construct(\Rexlabs\Smokescreen\Smokescreen $smokescreen, array $config = []) |
|
| 99 | + public function __construct(\Rexlabs\Smokescreen\Smokescreen $smokescreen, array $config = [ ]) |
|
| 100 | 100 | { |
| 101 | 101 | $this->smokescreen = $smokescreen; |
| 102 | 102 | $this->setConfig($config); |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * |
| 111 | 111 | * @return static |
| 112 | 112 | */ |
| 113 | - public static function make(\Rexlabs\Smokescreen\Smokescreen $smokescreen = null, array $config = []) |
|
| 113 | + public static function make(\Rexlabs\Smokescreen\Smokescreen $smokescreen = null, array $config = [ ]) |
|
| 114 | 114 | { |
| 115 | 115 | return new static($smokescreen ?? new \Rexlabs\Smokescreen\Smokescreen(), $config); |
| 116 | 116 | } |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | } elseif ($data instanceof EloquentBuilder) { |
| 254 | 254 | $data = $data->get(); |
| 255 | 255 | } elseif ($data instanceof Model) { |
| 256 | - $data = new Collection([$data]); |
|
| 256 | + $data = new Collection([ $data ]); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | // Create a new collection resource |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | */ |
| 408 | 408 | public function inject($key, $data) |
| 409 | 409 | { |
| 410 | - $this->injections[$key] = $data; |
|
| 410 | + $this->injections[ $key ] = $data; |
|
| 411 | 411 | |
| 412 | 412 | return $this; |
| 413 | 413 | } |
@@ -458,8 +458,8 @@ discard block |
||
| 458 | 458 | if ($this->smokescreen->getTransformerResolver() === null) { |
| 459 | 459 | $this->smokescreen->setTransformerResolver( |
| 460 | 460 | new TransformerResolver( |
| 461 | - $this->config['transformer_namespace'] ?? 'App\\Transformers', |
|
| 462 | - $this->config['transformer_name'] ?? '{ModelName}Transformer' |
|
| 461 | + $this->config[ 'transformer_namespace' ] ?? 'App\\Transformers', |
|
| 462 | + $this->config[ 'transformer_name' ] ?? '{ModelName}Transformer' |
|
| 463 | 463 | ) |
| 464 | 464 | ); |
| 465 | 465 | } |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | return $this->autoParseIncludes; |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | - return $this->config['include_key'] ?? 'include'; |
|
| 515 | + return $this->config[ 'include_key' ] ?? 'include'; |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | /** |
@@ -552,7 +552,7 @@ discard block |
||
| 552 | 552 | * |
| 553 | 553 | * @see Smokescreen::toArray() |
| 554 | 554 | */ |
| 555 | - public function response(int $statusCode = 200, array $headers = [], int $options = 0): JsonResponse |
|
| 555 | + public function response(int $statusCode = 200, array $headers = [ ], int $options = 0): JsonResponse |
|
| 556 | 556 | { |
| 557 | 557 | // Response will only be generated once. use clearResponse() to clear. |
| 558 | 558 | if ($this->response === null) { |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | * @see Smokescreen::toArray() |
| 581 | 581 | * @see Smokescreen::response() |
| 582 | 582 | */ |
| 583 | - public function freshResponse(int $statusCode = 200, array $headers = [], int $options = 0): JsonResponse |
|
| 583 | + public function freshResponse(int $statusCode = 200, array $headers = [ ], int $options = 0): JsonResponse |
|
| 584 | 584 | { |
| 585 | 585 | $this->clearResponse(); |
| 586 | 586 | |
@@ -697,26 +697,26 @@ discard block |
||
| 697 | 697 | */ |
| 698 | 698 | protected function setConfig(array $config) |
| 699 | 699 | { |
| 700 | - if (!empty($config['default_serializer'])) { |
|
| 701 | - $serializer = $config['default_serializer']; |
|
| 700 | + if (!empty($config[ 'default_serializer' ])) { |
|
| 701 | + $serializer = $config[ 'default_serializer' ]; |
|
| 702 | 702 | if (\is_string($serializer)) { |
| 703 | 703 | // Given serializer is expected to be a class path |
| 704 | 704 | // Instantiate via the container |
| 705 | 705 | $serializer = app()->make($serializer); |
| 706 | 706 | } |
| 707 | 707 | $this->serializeWith($serializer); |
| 708 | - unset($config['default_serializer']); |
|
| 708 | + unset($config[ 'default_serializer' ]); |
|
| 709 | 709 | } |
| 710 | 710 | |
| 711 | - if (!empty($config['default_transformer_resolver'])) { |
|
| 712 | - $transformerResolver = $config['default_transformer_resolver']; |
|
| 711 | + if (!empty($config[ 'default_transformer_resolver' ])) { |
|
| 712 | + $transformerResolver = $config[ 'default_transformer_resolver' ]; |
|
| 713 | 713 | if (\is_string($transformerResolver)) { |
| 714 | 714 | // Given transformer resolver is expected to be a class path |
| 715 | 715 | // Instantiate via the container |
| 716 | 716 | $transformerResolver = app()->make($transformerResolver); |
| 717 | 717 | } |
| 718 | 718 | $this->resolveTransformerVia($transformerResolver); |
| 719 | - unset($config['default_transformer_resolver']); |
|
| 719 | + unset($config[ 'default_transformer_resolver' ]); |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | $this->config = $config; |
@@ -43,8 +43,8 @@ |
||
| 43 | 43 | { |
| 44 | 44 | $this->app->singleton( |
| 45 | 45 | Smokescreen::class, |
| 46 | - function () { |
|
| 47 | - return new Smokescreen(new \Rexlabs\Smokescreen\Smokescreen(), config('smokescreen', [])); |
|
| 46 | + function() { |
|
| 47 | + return new Smokescreen(new \Rexlabs\Smokescreen\Smokescreen(), config('smokescreen', [ ])); |
|
| 48 | 48 | } |
| 49 | 49 | ); |
| 50 | 50 | $this->app->alias(Smokescreen::class, 'smokescreen'); |
@@ -70,18 +70,18 @@ discard block |
||
| 70 | 70 | */ |
| 71 | 71 | public function getIncludes(): array |
| 72 | 72 | { |
| 73 | - $includes = []; |
|
| 73 | + $includes = [ ]; |
|
| 74 | 74 | collect((new ReflectionClass($this->getModel()))->getMethods(ReflectionMethod::IS_PUBLIC)) |
| 75 | 75 | ->filter( |
| 76 | - function (ReflectionMethod $method) { |
|
| 76 | + function(ReflectionMethod $method) { |
|
| 77 | 77 | // We're not interested in inherited methods |
| 78 | 78 | return $method->getDeclaringClass()->getName() === $this->getModelClass(); |
| 79 | 79 | } |
| 80 | 80 | )->each( |
| 81 | - function (ReflectionMethod $method) use (&$includes) { |
|
| 81 | + function(ReflectionMethod $method) use (&$includes) { |
|
| 82 | 82 | // Only include if we can resolve a resource type |
| 83 | 83 | if (($type = $this->getResourceType($method)) !== null) { |
| 84 | - $includes[$method->getName()] = "relation|{$type}"; |
|
| 84 | + $includes[ $method->getName() ] = "relation|{$type}"; |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | ); |
@@ -96,11 +96,11 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | public function getDeclaredProperties(): array |
| 98 | 98 | { |
| 99 | - $props = []; |
|
| 99 | + $props = [ ]; |
|
| 100 | 100 | $table = $this->getModel()->getTable(); |
| 101 | 101 | foreach (Schema::getColumnListing($table) as $column) { |
| 102 | 102 | $type = Schema::getColumnType($table, $column); |
| 103 | - $props[$column] = $this->schemaTypesMap[$type] ?? null; |
|
| 103 | + $props[ $column ] = $this->schemaTypesMap[ $type ] ?? null; |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | return $props; |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | public function getDefaultProperties(): array |
| 115 | 115 | { |
| 116 | - return []; |
|
| 116 | + return [ ]; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | |
| 190 | 190 | $relation = class_basename($returnType); |
| 191 | 191 | |
| 192 | - return $this->relationsMap[$relation] ?? null; |
|
| 192 | + return $this->relationsMap[ $relation ] ?? null; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | $keyPattern = implode( |
| 209 | 209 | '|', |
| 210 | 210 | array_map( |
| 211 | - function ($key) { |
|
| 211 | + function($key) { |
|
| 212 | 212 | return preg_quote($key, '/'); |
| 213 | 213 | }, |
| 214 | 214 | array_keys($this->relationsMap) |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | ); |
| 217 | 217 | foreach (explode('|', $returnTypes) as $returnType) { |
| 218 | 218 | if (preg_match("/($keyPattern)\$/i", $returnType, $match)) { |
| 219 | - return $this->relationsMap[$match[1]] ?? null; |
|
| 219 | + return $this->relationsMap[ $match[ 1 ] ] ?? null; |
|
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | } |
@@ -239,11 +239,11 @@ discard block |
||
| 239 | 239 | $numLines = $method->getEndLine() - $startLine; |
| 240 | 240 | $body = implode('', \array_slice(file($method->getFileName()), $startLine, $numLines)); |
| 241 | 241 | if (preg_match('/^\s*return\s+(.+?);/ms', $body, $match)) { |
| 242 | - $returnStmt = $match[1]; |
|
| 242 | + $returnStmt = $match[ 1 ]; |
|
| 243 | 243 | foreach (array_keys($this->relationsMap) as $returnType) { |
| 244 | 244 | // Find "->hasMany(" etc. |
| 245 | 245 | if (preg_match('/->' . preg_quote($returnType, '/') . '\(/i', $returnStmt)) { |
| 246 | - return $this->relationsMap[$returnType]; |
|
| 246 | + return $this->relationsMap[ $returnType ]; |
|
| 247 | 247 | } |
| 248 | 248 | } |
| 249 | 249 | } |