@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | $class = $this->classify($name); |
| 40 | 40 | $postfix = $this->elementPostfix($element); |
| 41 | 41 | |
| 42 | - return \str_ends_with($class, $postfix) ? $class : $class . $postfix; |
|
| 42 | + return \str_ends_with($class, $postfix) ? $class : $class.$postfix; |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | public function classNamespace(string $element, string $name = ''): string |
@@ -47,15 +47,15 @@ discard block |
||
| 47 | 47 | $localNamespace = \trim($this->getOption($element, 'namespace', ''), '\\'); |
| 48 | 48 | ['namespace' => $namespace] = $this->parseName($name); |
| 49 | 49 | |
| 50 | - if (!empty($namespace)) { |
|
| 51 | - $localNamespace .= '\\' . $this->classify($namespace); |
|
| 50 | + if (!empty($namespace)){ |
|
| 51 | + $localNamespace .= '\\'.$this->classify($namespace); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - if (empty($this->baseNamespace($element))) { |
|
| 54 | + if (empty($this->baseNamespace($element))){ |
|
| 55 | 55 | return $localNamespace; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - return \trim($this->baseNamespace($element) . '\\' . $localNamespace, '\\'); |
|
| 58 | + return \trim($this->baseNamespace($element).'\\'.$localNamespace, '\\'); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | public function classFilename(string $element, string $name): string |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | return $this->joinPathChunks([ |
| 67 | 67 | $this->baseDirectory(), |
| 68 | 68 | \str_replace('\\', '/', $namespace), |
| 69 | - $this->className($element, $name) . '.php', |
|
| 69 | + $this->className($element, $name).'.php', |
|
| 70 | 70 | ], '/'); |
| 71 | 71 | } |
| 72 | 72 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | { |
| 78 | 78 | $class = $this->getOption($element, 'class'); |
| 79 | 79 | |
| 80 | - if (empty($class)) { |
|
| 80 | + if (empty($class)){ |
|
| 81 | 81 | throw new ScaffolderException( |
| 82 | 82 | \sprintf("Unable to scaffold '%s', no declaration class found", $element) |
| 83 | 83 | ); |
@@ -101,11 +101,11 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | private function getOption(string $element, string $section, mixed $default = null): mixed |
| 103 | 103 | { |
| 104 | - if (!isset($this->config['declarations'][$element])) { |
|
| 104 | + if (!isset($this->config['declarations'][$element])){ |
|
| 105 | 105 | throw new ScaffolderException(\sprintf("Undefined declaration '%s'.", $element)); |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - if (\array_key_exists($section, $this->config['declarations'][$element])) { |
|
| 108 | + if (\array_key_exists($section, $this->config['declarations'][$element])){ |
|
| 109 | 109 | return $this->config['declarations'][$element][$section]; |
| 110 | 110 | } |
| 111 | 111 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | { |
| 122 | 122 | $name = \str_replace('/', '\\', $name); |
| 123 | 123 | |
| 124 | - if (str_contains($name, '\\')) { |
|
| 124 | + if (str_contains($name, '\\')){ |
|
| 125 | 125 | $names = \explode('\\', $name); |
| 126 | 126 | $class = \array_pop($names); |
| 127 | 127 | |
@@ -134,8 +134,8 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | private function baseNamespace(string $element): string |
| 136 | 136 | { |
| 137 | - if (\array_key_exists('baseNamespace', $this->config['declarations'][$element])) { |
|
| 138 | - return \trim((string) $this->getOption($element, 'baseNamespace', ''), '\\'); |
|
| 137 | + if (\array_key_exists('baseNamespace', $this->config['declarations'][$element])){ |
|
| 138 | + return \trim((string)$this->getOption($element, 'baseNamespace', ''), '\\'); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | return \trim($this->config['namespace'], '\\'); |
@@ -145,12 +145,12 @@ discard block |
||
| 145 | 145 | { |
| 146 | 146 | $firstChunkIterated = false; |
| 147 | 147 | $joinedPath = ''; |
| 148 | - foreach ($chunks as $chunk) { |
|
| 149 | - if (!$firstChunkIterated) { |
|
| 148 | + foreach ($chunks as $chunk){ |
|
| 149 | + if (!$firstChunkIterated){ |
|
| 150 | 150 | $firstChunkIterated = true; |
| 151 | 151 | $joinedPath = $chunk; |
| 152 | - } else { |
|
| 153 | - $joinedPath = \rtrim($joinedPath, $joint) . $joint . \ltrim($chunk, $joint); |
|
| 152 | + }else{ |
|
| 153 | + $joinedPath = \rtrim($joinedPath, $joint).$joint.\ltrim($chunk, $joint); |
|
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | |
| 160 | 160 | private function classify(string $name): string |
| 161 | 161 | { |
| 162 | - return ( new InflectorFactory() ) |
|
| 162 | + return (new InflectorFactory()) |
|
| 163 | 163 | ->build() |
| 164 | 164 | ->classify($name); |
| 165 | 165 | } |
@@ -47,11 +47,13 @@ discard block |
||
| 47 | 47 | $localNamespace = \trim($this->getOption($element, 'namespace', ''), '\\'); |
| 48 | 48 | ['namespace' => $namespace] = $this->parseName($name); |
| 49 | 49 | |
| 50 | - if (!empty($namespace)) { |
|
| 50 | + if (!empty($namespace)) |
|
| 51 | + { |
|
| 51 | 52 | $localNamespace .= '\\' . $this->classify($namespace); |
| 52 | 53 | } |
| 53 | 54 | |
| 54 | - if (empty($this->baseNamespace($element))) { |
|
| 55 | + if (empty($this->baseNamespace($element))) |
|
| 56 | + { |
|
| 55 | 57 | return $localNamespace; |
| 56 | 58 | } |
| 57 | 59 | |
@@ -77,7 +79,8 @@ discard block |
||
| 77 | 79 | { |
| 78 | 80 | $class = $this->getOption($element, 'class'); |
| 79 | 81 | |
| 80 | - if (empty($class)) { |
|
| 82 | + if (empty($class)) |
|
| 83 | + { |
|
| 81 | 84 | throw new ScaffolderException( |
| 82 | 85 | \sprintf("Unable to scaffold '%s', no declaration class found", $element) |
| 83 | 86 | ); |
@@ -101,11 +104,13 @@ discard block |
||
| 101 | 104 | |
| 102 | 105 | private function getOption(string $element, string $section, mixed $default = null): mixed |
| 103 | 106 | { |
| 104 | - if (!isset($this->config['declarations'][$element])) { |
|
| 107 | + if (!isset($this->config['declarations'][$element])) |
|
| 108 | + { |
|
| 105 | 109 | throw new ScaffolderException(\sprintf("Undefined declaration '%s'.", $element)); |
| 106 | 110 | } |
| 107 | 111 | |
| 108 | - if (\array_key_exists($section, $this->config['declarations'][$element])) { |
|
| 112 | + if (\array_key_exists($section, $this->config['declarations'][$element])) |
|
| 113 | + { |
|
| 109 | 114 | return $this->config['declarations'][$element][$section]; |
| 110 | 115 | } |
| 111 | 116 | |
@@ -121,7 +126,8 @@ discard block |
||
| 121 | 126 | { |
| 122 | 127 | $name = \str_replace('/', '\\', $name); |
| 123 | 128 | |
| 124 | - if (str_contains($name, '\\')) { |
|
| 129 | + if (str_contains($name, '\\')) |
|
| 130 | + { |
|
| 125 | 131 | $names = \explode('\\', $name); |
| 126 | 132 | $class = \array_pop($names); |
| 127 | 133 | |
@@ -134,7 +140,8 @@ discard block |
||
| 134 | 140 | |
| 135 | 141 | private function baseNamespace(string $element): string |
| 136 | 142 | { |
| 137 | - if (\array_key_exists('baseNamespace', $this->config['declarations'][$element])) { |
|
| 143 | + if (\array_key_exists('baseNamespace', $this->config['declarations'][$element])) |
|
| 144 | + { |
|
| 138 | 145 | return \trim((string) $this->getOption($element, 'baseNamespace', ''), '\\'); |
| 139 | 146 | } |
| 140 | 147 | |
@@ -145,11 +152,15 @@ discard block |
||
| 145 | 152 | { |
| 146 | 153 | $firstChunkIterated = false; |
| 147 | 154 | $joinedPath = ''; |
| 148 | - foreach ($chunks as $chunk) { |
|
| 149 | - if (!$firstChunkIterated) { |
|
| 155 | + foreach ($chunks as $chunk) |
|
| 156 | + { |
|
| 157 | + if (!$firstChunkIterated) |
|
| 158 | + { |
|
| 150 | 159 | $firstChunkIterated = true; |
| 151 | 160 | $joinedPath = $chunk; |
| 152 | - } else { |
|
| 161 | + } |
|
| 162 | + else |
|
| 163 | + { |
|
| 153 | 164 | $joinedPath = \rtrim($joinedPath, $joint) . $joint . \ltrim($chunk, $joint); |
| 154 | 165 | } |
| 155 | 166 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | namespace Spiral\Scaffolder; |
| 6 | 6 | |
| 7 | -if (!\function_exists('trimPostfix')) { |
|
| 7 | +if (!\function_exists('trimPostfix')){ |
|
| 8 | 8 | /** |
| 9 | 9 | * @internal |
| 10 | 10 | */ |
@@ -16,19 +16,19 @@ discard block |
||
| 16 | 16 | } |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | -if (!\function_exists('isAssociativeArray')) { |
|
| 19 | +if (!\function_exists('isAssociativeArray')){ |
|
| 20 | 20 | /** |
| 21 | 21 | * @internal |
| 22 | 22 | */ |
| 23 | 23 | function isAssociativeArray(array $array): bool |
| 24 | 24 | { |
| 25 | 25 | $keys = []; |
| 26 | - foreach ($array as $key => $_) { |
|
| 27 | - if (!\is_int($key)) { |
|
| 26 | + foreach ($array as $key => $_){ |
|
| 27 | + if (!\is_int($key)){ |
|
| 28 | 28 | return true; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - if ($key !== \count($keys)) { |
|
| 31 | + if ($key !== \count($keys)){ |
|
| 32 | 32 | return true; |
| 33 | 33 | } |
| 34 | 34 | |
@@ -39,13 +39,13 @@ discard block |
||
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | -if (!\function_exists('defineArrayType')) { |
|
| 42 | +if (!\function_exists('defineArrayType')){ |
|
| 43 | 43 | /** |
| 44 | 44 | * @internal |
| 45 | 45 | */ |
| 46 | 46 | function defineArrayType(array $array, string $failureType = null): ?string |
| 47 | 47 | { |
| 48 | - $types = \array_map(static fn ($value): string => \gettype($value), $array); |
|
| 48 | + $types = \array_map(static fn ($value) : string => \gettype($value), $array); |
|
| 49 | 49 | |
| 50 | 50 | $types = \array_unique($types); |
| 51 | 51 | |
@@ -4,7 +4,8 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | namespace Spiral\Scaffolder; |
| 6 | 6 | |
| 7 | -if (!\function_exists('trimPostfix')) { |
|
| 7 | +if (!\function_exists('trimPostfix')) |
|
| 8 | +{ |
|
| 8 | 9 | /** |
| 9 | 10 | * @internal |
| 10 | 11 | */ |
@@ -16,19 +17,23 @@ discard block |
||
| 16 | 17 | } |
| 17 | 18 | } |
| 18 | 19 | |
| 19 | -if (!\function_exists('isAssociativeArray')) { |
|
| 20 | +if (!\function_exists('isAssociativeArray')) |
|
| 21 | +{ |
|
| 20 | 22 | /** |
| 21 | 23 | * @internal |
| 22 | 24 | */ |
| 23 | 25 | function isAssociativeArray(array $array): bool |
| 24 | 26 | { |
| 25 | 27 | $keys = []; |
| 26 | - foreach ($array as $key => $_) { |
|
| 27 | - if (!\is_int($key)) { |
|
| 28 | + foreach ($array as $key => $_) |
|
| 29 | + { |
|
| 30 | + if (!\is_int($key)) |
|
| 31 | + { |
|
| 28 | 32 | return true; |
| 29 | 33 | } |
| 30 | 34 | |
| 31 | - if ($key !== \count($keys)) { |
|
| 35 | + if ($key !== \count($keys)) |
|
| 36 | + { |
|
| 32 | 37 | return true; |
| 33 | 38 | } |
| 34 | 39 | |
@@ -39,7 +44,8 @@ discard block |
||
| 39 | 44 | } |
| 40 | 45 | } |
| 41 | 46 | |
| 42 | -if (!\function_exists('defineArrayType')) { |
|
| 47 | +if (!\function_exists('defineArrayType')) |
|
| 48 | +{ |
|
| 43 | 49 | /** |
| 44 | 50 | * @internal |
| 45 | 51 | */ |
@@ -43,8 +43,8 @@ |
||
| 43 | 43 | $declaration = $this->createDeclaration(ConfigDeclaration::class); |
| 44 | 44 | |
| 45 | 45 | $declaration->create( |
| 46 | - (bool) $this->option('reverse'), |
|
| 47 | - (string) $this->argument('name') |
|
| 46 | + (bool)$this->option('reverse'), |
|
| 47 | + (string)$this->argument('name') |
|
| 48 | 48 | ); |
| 49 | 49 | |
| 50 | 50 | $this->writeDeclaration($declaration); |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | protected FilesInterface $files, |
| 20 | 20 | ContainerInterface $container, |
| 21 | 21 | private readonly FactoryInterface $factory |
| 22 | - ) { |
|
| 22 | + ){ |
|
| 23 | 23 | $this->setContainer($container); |
| 24 | 24 | |
| 25 | 25 | parent::__construct(); |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | return $this->factory->make( |
| 37 | 37 | $class, |
| 38 | 38 | [ |
| 39 | - 'name' => (string) $this->argument('name'), |
|
| 39 | + 'name' => (string)$this->argument('name'), |
|
| 40 | 40 | 'comment' => $this->option('comment'), |
| 41 | 41 | ] + $this->config->declarationOptions($class::TYPE) |
| 42 | 42 | ); |
@@ -47,11 +47,11 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | protected function writeDeclaration(DeclarationInterface $declaration): void |
| 49 | 49 | { |
| 50 | - $filename = $this->config->classFilename($declaration::TYPE, (string) $this->argument('name')); |
|
| 50 | + $filename = $this->config->classFilename($declaration::TYPE, (string)$this->argument('name')); |
|
| 51 | 51 | $filename = $this->files->normalizePath($filename); |
| 52 | 52 | $className = $declaration->getClass()->getName(); |
| 53 | 53 | |
| 54 | - if ($this->files->exists($filename)) { |
|
| 54 | + if ($this->files->exists($filename)){ |
|
| 55 | 55 | $this->writeln( |
| 56 | 56 | \sprintf("<fg=red>Unable to create '<comment>%s</comment>' declaration, ", $className) |
| 57 | 57 | . \sprintf("file '<comment>%s</comment>' already exists.</fg=red>", $filename) |
@@ -51,7 +51,8 @@ |
||
| 51 | 51 | $filename = $this->files->normalizePath($filename); |
| 52 | 52 | $className = $declaration->getClass()->getName(); |
| 53 | 53 | |
| 54 | - if ($this->files->exists($filename)) { |
|
| 54 | + if ($this->files->exists($filename)) |
|
| 55 | + { |
|
| 55 | 56 | $this->writeln( |
| 56 | 57 | \sprintf("<fg=red>Unable to create '<comment>%s</comment>' declaration, ", $className) |
| 57 | 58 | . \sprintf("file '<comment>%s</comment>' already exists.</fg=red>", $filename) |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | ['name', InputArgument::REQUIRED, 'Command name'], |
| 17 | 17 | ['alias', InputArgument::OPTIONAL, 'Command id/alias'], |
| 18 | 18 | ]; |
| 19 | - protected const OPTIONS = [ |
|
| 19 | + protected const OPTIONS = [ |
|
| 20 | 20 | [ |
| 21 | 21 | 'description', |
| 22 | 22 | 'd', |
@@ -38,8 +38,8 @@ discard block |
||
| 38 | 38 | { |
| 39 | 39 | $declaration = $this->createDeclaration(CommandDeclaration::class); |
| 40 | 40 | |
| 41 | - $declaration->setAlias((string) ($this->argument('alias') ?? $this->argument('name'))); |
|
| 42 | - $declaration->setDescription((string) $this->option('description')); |
|
| 41 | + $declaration->setAlias((string)($this->argument('alias') ?? $this->argument('name'))); |
|
| 42 | + $declaration->setDescription((string)$this->option('description')); |
|
| 43 | 43 | |
| 44 | 44 | $this->writeDeclaration($declaration); |
| 45 | 45 | |
@@ -43,11 +43,11 @@ |
||
| 43 | 43 | { |
| 44 | 44 | $declaration = $this->createDeclaration(ControllerDeclaration::class); |
| 45 | 45 | |
| 46 | - foreach ($this->option('action') as $action) { |
|
| 46 | + foreach ($this->option('action') as $action){ |
|
| 47 | 47 | $declaration->addAction($action); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - if ((bool)$this->option('prototype')) { |
|
| 50 | + if ((bool)$this->option('prototype')){ |
|
| 51 | 51 | $declaration->addPrototypeTrait(); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -43,11 +43,13 @@ |
||
| 43 | 43 | { |
| 44 | 44 | $declaration = $this->createDeclaration(ControllerDeclaration::class); |
| 45 | 45 | |
| 46 | - foreach ($this->option('action') as $action) { |
|
| 46 | + foreach ($this->option('action') as $action) |
|
| 47 | + { |
|
| 47 | 48 | $declaration->addAction($action); |
| 48 | 49 | } |
| 49 | 50 | |
| 50 | - if ((bool)$this->option('prototype')) { |
|
| 51 | + if ((bool)$this->option('prototype')) |
|
| 52 | + { |
|
| 51 | 53 | $declaration->addPrototypeTrait(); |
| 52 | 54 | } |
| 53 | 55 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | public function __construct( |
| 27 | 27 | private readonly ConfiguratorInterface $config, |
| 28 | 28 | private readonly KernelInterface $kernel |
| 29 | - ) { |
|
| 29 | + ){ |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function init(ConsoleBootloader $console): void |
@@ -38,9 +38,9 @@ discard block |
||
| 38 | 38 | $console->addCommand(Command\JobHandlerCommand::class); |
| 39 | 39 | $console->addCommand(Command\MiddlewareCommand::class); |
| 40 | 40 | |
| 41 | - try { |
|
| 41 | + try{ |
|
| 42 | 42 | $defaultNamespace = (new ReflectionClass($this->kernel))->getNamespaceName(); |
| 43 | - } catch (ReflectionException) { |
|
| 43 | + }catch (ReflectionException){ |
|
| 44 | 44 | $defaultNamespace = ''; |
| 45 | 45 | } |
| 46 | 46 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * Base directory for generated classes, class will be automatically localed into sub directory |
| 56 | 56 | * using given namespace. |
| 57 | 57 | */ |
| 58 | - 'directory' => directory('app') . 'src/', |
|
| 58 | + 'directory' => directory('app').'src/', |
|
| 59 | 59 | |
| 60 | 60 | /* |
| 61 | 61 | * Default namespace to be applied for every generated class. By default uses Kernel namespace |
@@ -38,9 +38,12 @@ |
||
| 38 | 38 | $console->addCommand(Command\JobHandlerCommand::class); |
| 39 | 39 | $console->addCommand(Command\MiddlewareCommand::class); |
| 40 | 40 | |
| 41 | - try { |
|
| 41 | + try |
|
| 42 | + { |
|
| 42 | 43 | $defaultNamespace = (new ReflectionClass($this->kernel))->getNamespaceName(); |
| 43 | - } catch (ReflectionException) { |
|
| 44 | + } |
|
| 45 | + catch (ReflectionException) |
|
| 46 | + { |
|
| 44 | 47 | $defaultNamespace = ''; |
| 45 | 48 | } |
| 46 | 49 | |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | public function get(array $values): array |
| 27 | 27 | { |
| 28 | 28 | $output = []; |
| 29 | - foreach ($values as $key => $value) { |
|
| 29 | + foreach ($values as $key => $value){ |
|
| 30 | 30 | $output[$key] = self::TYPE_DEFAULTS[\gettype($value)] ?? null; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -26,7 +26,8 @@ |
||
| 26 | 26 | public function get(array $values): array |
| 27 | 27 | { |
| 28 | 28 | $output = []; |
| 29 | - foreach ($values as $key => $value) { |
|
| 29 | + foreach ($values as $key => $value) |
|
| 30 | + { |
|
| 30 | 31 | $output[$key] = self::TYPE_DEFAULTS[\gettype($value)] ?? null; |
| 31 | 32 | } |
| 32 | 33 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | public function getAnnotation(mixed $value): string |
| 28 | 28 | { |
| 29 | - if (\is_array($value)) { |
|
| 29 | + if (\is_array($value)){ |
|
| 30 | 30 | return $this->arrayAnnotationString($value); |
| 31 | 31 | } |
| 32 | 32 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | private function arrayAnnotationString(array $value): string |
| 42 | 42 | { |
| 43 | 43 | $types = []; |
| 44 | - foreach ($value as $item) { |
|
| 44 | + foreach ($value as $item){ |
|
| 45 | 45 | $types[] = \gettype($item); |
| 46 | 46 | } |
| 47 | 47 | $types = \array_unique($types); |
@@ -26,7 +26,8 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | public function getAnnotation(mixed $value): string |
| 28 | 28 | { |
| 29 | - if (\is_array($value)) { |
|
| 29 | + if (\is_array($value)) |
|
| 30 | + { |
|
| 30 | 31 | return $this->arrayAnnotationString($value); |
| 31 | 32 | } |
| 32 | 33 | |
@@ -41,7 +42,8 @@ discard block |
||
| 41 | 42 | private function arrayAnnotationString(array $value): string |
| 42 | 43 | { |
| 43 | 44 | $types = []; |
| 44 | - foreach ($value as $item) { |
|
| 45 | + foreach ($value as $item) |
|
| 46 | + { |
|
| 45 | 47 | $types[] = \gettype($item); |
| 46 | 48 | } |
| 47 | 49 | $types = \array_unique($types); |