@@ -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); |
@@ -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 | } |
@@ -91,9 +91,9 @@ discard block |
||
| 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) { |
|
| 95 | - return $directory.'\\'.$name; |
|
| 96 | - }, ['App\\Models', 'App\\Model', 'App']); |
|
| 94 | + $search = strpos($name, '\\') !== false ? [ $name ] : array_map(function($directory) use ($name) { |
|
| 95 | + return $directory . '\\' . $name; |
|
| 96 | + }, [ 'App\\Models', 'App\\Model', 'App' ]); |
|
| 97 | 97 | |
| 98 | 98 | // Check for a valid class. |
| 99 | 99 | foreach ($search as $class) { |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | */ |
| 188 | 188 | protected function getTransformerClass() |
| 189 | 189 | { |
| 190 | - return $this->getTransformerNamespace().'\\'.$this->getTransformerName(); |
|
| 190 | + return $this->getTransformerNamespace() . '\\' . $this->getTransformerName(); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -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 | /** |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | // $relation = lcfirst(class_basename($returnType)); |
| 172 | 172 | $relation = class_basename($returnType); |
| 173 | 173 | |
| 174 | - return $this->relationsMap[$relation] ?? null; |
|
| 174 | + return $this->relationsMap[ $relation ] ?? null; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -187,12 +187,12 @@ discard block |
||
| 187 | 187 | list($statement, $returnTypes) = $match; |
| 188 | 188 | |
| 189 | 189 | // Build a regex suitable for matching our relationship keys. EG. hasOne|hasMany... |
| 190 | - $keyPattern = implode('|', array_map(function ($key) { |
|
| 190 | + $keyPattern = implode('|', array_map(function($key) { |
|
| 191 | 191 | return preg_quote($key, '/'); |
| 192 | 192 | }, array_keys($this->relationsMap))); |
| 193 | 193 | foreach (explode('|', $returnTypes) as $returnType) { |
| 194 | 194 | if (preg_match("/($keyPattern)\$/i", $returnType, $match)) { |
| 195 | - return $this->relationsMap[$match[1]] ?? null; |
|
| 195 | + return $this->relationsMap[ $match[ 1 ] ] ?? null; |
|
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | 198 | } |
@@ -213,11 +213,11 @@ discard block |
||
| 213 | 213 | $numLines = $method->getEndLine() - $startLine; |
| 214 | 214 | $body = implode('', \array_slice(file($method->getFileName()), $startLine, $numLines)); |
| 215 | 215 | if (preg_match('/^\s*return\s+(.+?);/ms', $body, $match)) { |
| 216 | - $returnStmt = $match[1]; |
|
| 216 | + $returnStmt = $match[ 1 ]; |
|
| 217 | 217 | foreach (array_keys($this->relationsMap) as $returnType) { |
| 218 | 218 | // Find "->hasMany(" etc. |
| 219 | - if (preg_match('/->'.preg_quote($returnType, '/').'\(/i', $returnStmt)) { |
|
| 220 | - return $this->relationsMap[$returnType]; |
|
| 219 | + if (preg_match('/->' . preg_quote($returnType, '/') . '\(/i', $returnStmt)) { |
|
| 220 | + return $this->relationsMap[ $returnType ]; |
|
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | } |
@@ -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 | } |