@@ -130,8 +130,8 @@ discard block |
||
| 130 | 130 | public function initAnnotations(ContainerInterface $container, bool $reset = false): void |
| 131 | 131 | { |
| 132 | 132 | $prototyped = $this->memory->loadData('prototyped'); |
| 133 | - if (!$reset && $prototyped !== null) { |
|
| 134 | - foreach ($prototyped as $property => $class) { |
|
| 133 | + if (!$reset && $prototyped !== null){ |
|
| 134 | + foreach ($prototyped as $property => $class){ |
|
| 135 | 135 | $this->bindProperty($property, $class); |
| 136 | 136 | } |
| 137 | 137 | |
@@ -143,10 +143,10 @@ discard block |
||
| 143 | 143 | $reader = $container->get(ReaderInterface::class); |
| 144 | 144 | |
| 145 | 145 | $prototyped = []; |
| 146 | - foreach ($locator->getClasses() as $class) { |
|
| 146 | + foreach ($locator->getClasses() as $class){ |
|
| 147 | 147 | $meta = $reader->firstClassMetadata($class, Prototyped::class); |
| 148 | 148 | |
| 149 | - if ($meta === null) { |
|
| 149 | + if ($meta === null){ |
|
| 150 | 150 | continue; |
| 151 | 151 | } |
| 152 | 152 | |
@@ -162,19 +162,19 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | public function initCycle(ContainerInterface $container): void |
| 164 | 164 | { |
| 165 | - if (!$container->has(SchemaInterface::class)) { |
|
| 165 | + if (!$container->has(SchemaInterface::class)){ |
|
| 166 | 166 | return; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** @var ORM\SchemaInterface|null $schema */ |
| 170 | 170 | $schema = $container->get(SchemaInterface::class); |
| 171 | - if ($schema === null) { |
|
| 171 | + if ($schema === null){ |
|
| 172 | 172 | return; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - foreach ($schema->getRoles() as $role) { |
|
| 175 | + foreach ($schema->getRoles() as $role){ |
|
| 176 | 176 | $repository = $schema->define($role, SchemaInterface::REPOSITORY); |
| 177 | - if ($repository === Repository::class || $repository === null) { |
|
| 177 | + if ($repository === Repository::class || $repository === null){ |
|
| 178 | 178 | // default repository can not be wired |
| 179 | 179 | continue; |
| 180 | 180 | } |
@@ -185,23 +185,23 @@ discard block |
||
| 185 | 185 | |
| 186 | 186 | private function initDefaults(ContainerInterface $container): void |
| 187 | 187 | { |
| 188 | - foreach (self::DEFAULT_SHORTCUTS as $property => $shortcut) { |
|
| 189 | - if (is_array($shortcut) && isset($shortcut['resolve'])) { |
|
| 190 | - if (isset($shortcut['with'])) { |
|
| 188 | + foreach (self::DEFAULT_SHORTCUTS as $property => $shortcut){ |
|
| 189 | + if (is_array($shortcut) && isset($shortcut['resolve'])){ |
|
| 190 | + if (isset($shortcut['with'])){ |
|
| 191 | 191 | // check dependencies |
| 192 | - foreach ($shortcut['with'] as $dep) { |
|
| 193 | - if (!class_exists($dep, true) && !interface_exists($dep, true)) { |
|
| 192 | + foreach ($shortcut['with'] as $dep){ |
|
| 193 | + if (!class_exists($dep, true) && !interface_exists($dep, true)){ |
|
| 194 | 194 | continue 2; |
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - try { |
|
| 199 | + try{ |
|
| 200 | 200 | $target = $container->get($shortcut['resolve']); |
| 201 | - if (is_object($target)) { |
|
| 201 | + if (is_object($target)){ |
|
| 202 | 202 | $this->bindProperty($property, get_class($target)); |
| 203 | 203 | } |
| 204 | - } catch (ContainerExceptionInterface $e) { |
|
| 204 | + }catch (ContainerExceptionInterface $e){ |
|
| 205 | 205 | continue; |
| 206 | 206 | } |
| 207 | 207 | |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | is_string($shortcut) |
| 213 | 213 | && (class_exists($shortcut, true) |
| 214 | 214 | || interface_exists($shortcut, true)) |
| 215 | - ) { |
|
| 215 | + ){ |
|
| 216 | 216 | $this->bindProperty($property, $shortcut); |
| 217 | 217 | } |
| 218 | 218 | } |
@@ -130,8 +130,10 @@ discard block |
||
| 130 | 130 | public function initAnnotations(ContainerInterface $container, bool $reset = false): void |
| 131 | 131 | { |
| 132 | 132 | $prototyped = $this->memory->loadData('prototyped'); |
| 133 | - if (!$reset && $prototyped !== null) { |
|
| 134 | - foreach ($prototyped as $property => $class) { |
|
| 133 | + if (!$reset && $prototyped !== null) |
|
| 134 | + { |
|
| 135 | + foreach ($prototyped as $property => $class) |
|
| 136 | + { |
|
| 135 | 137 | $this->bindProperty($property, $class); |
| 136 | 138 | } |
| 137 | 139 | |
@@ -143,10 +145,12 @@ discard block |
||
| 143 | 145 | $reader = $container->get(ReaderInterface::class); |
| 144 | 146 | |
| 145 | 147 | $prototyped = []; |
| 146 | - foreach ($locator->getClasses() as $class) { |
|
| 148 | + foreach ($locator->getClasses() as $class) |
|
| 149 | + { |
|
| 147 | 150 | $meta = $reader->firstClassMetadata($class, Prototyped::class); |
| 148 | 151 | |
| 149 | - if ($meta === null) { |
|
| 152 | + if ($meta === null) |
|
| 153 | + { |
|
| 150 | 154 | continue; |
| 151 | 155 | } |
| 152 | 156 | |
@@ -162,19 +166,23 @@ discard block |
||
| 162 | 166 | */ |
| 163 | 167 | public function initCycle(ContainerInterface $container): void |
| 164 | 168 | { |
| 165 | - if (!$container->has(SchemaInterface::class)) { |
|
| 169 | + if (!$container->has(SchemaInterface::class)) |
|
| 170 | + { |
|
| 166 | 171 | return; |
| 167 | 172 | } |
| 168 | 173 | |
| 169 | 174 | /** @var ORM\SchemaInterface|null $schema */ |
| 170 | 175 | $schema = $container->get(SchemaInterface::class); |
| 171 | - if ($schema === null) { |
|
| 176 | + if ($schema === null) |
|
| 177 | + { |
|
| 172 | 178 | return; |
| 173 | 179 | } |
| 174 | 180 | |
| 175 | - foreach ($schema->getRoles() as $role) { |
|
| 181 | + foreach ($schema->getRoles() as $role) |
|
| 182 | + { |
|
| 176 | 183 | $repository = $schema->define($role, SchemaInterface::REPOSITORY); |
| 177 | - if ($repository === Repository::class || $repository === null) { |
|
| 184 | + if ($repository === Repository::class || $repository === null) |
|
| 185 | + { |
|
| 178 | 186 | // default repository can not be wired |
| 179 | 187 | continue; |
| 180 | 188 | } |
@@ -185,23 +193,32 @@ discard block |
||
| 185 | 193 | |
| 186 | 194 | private function initDefaults(ContainerInterface $container): void |
| 187 | 195 | { |
| 188 | - foreach (self::DEFAULT_SHORTCUTS as $property => $shortcut) { |
|
| 189 | - if (is_array($shortcut) && isset($shortcut['resolve'])) { |
|
| 190 | - if (isset($shortcut['with'])) { |
|
| 196 | + foreach (self::DEFAULT_SHORTCUTS as $property => $shortcut) |
|
| 197 | + { |
|
| 198 | + if (is_array($shortcut) && isset($shortcut['resolve'])) |
|
| 199 | + { |
|
| 200 | + if (isset($shortcut['with'])) |
|
| 201 | + { |
|
| 191 | 202 | // check dependencies |
| 192 | - foreach ($shortcut['with'] as $dep) { |
|
| 193 | - if (!class_exists($dep, true) && !interface_exists($dep, true)) { |
|
| 203 | + foreach ($shortcut['with'] as $dep) |
|
| 204 | + { |
|
| 205 | + if (!class_exists($dep, true) && !interface_exists($dep, true)) |
|
| 206 | + { |
|
| 194 | 207 | continue 2; |
| 195 | 208 | } |
| 196 | 209 | } |
| 197 | 210 | } |
| 198 | 211 | |
| 199 | - try { |
|
| 212 | + try |
|
| 213 | + { |
|
| 200 | 214 | $target = $container->get($shortcut['resolve']); |
| 201 | - if (is_object($target)) { |
|
| 215 | + if (is_object($target)) |
|
| 216 | + { |
|
| 202 | 217 | $this->bindProperty($property, get_class($target)); |
| 203 | 218 | } |
| 204 | - } catch (ContainerExceptionInterface $e) { |
|
| 219 | + } |
|
| 220 | + catch (ContainerExceptionInterface $e) |
|
| 221 | + { |
|
| 205 | 222 | continue; |
| 206 | 223 | } |
| 207 | 224 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public function __construct(Lexer $lexer = null, PrettyPrinterAbstract $printer = null) |
| 48 | 48 | { |
| 49 | - if ($lexer === null) { |
|
| 49 | + if ($lexer === null){ |
|
| 50 | 50 | $lexer = new Emulative([ |
| 51 | 51 | 'usedAttributes' => [ |
| 52 | 52 | 'comments', |
@@ -78,8 +78,8 @@ discard block |
||
| 78 | 78 | bool $useTypedProperties = false, |
| 79 | 79 | bool $noPhpDoc = false |
| 80 | 80 | ): string { |
| 81 | - if (empty($node->dependencies)) { |
|
| 82 | - if ($removeTrait) { |
|
| 81 | + if (empty($node->dependencies)){ |
|
| 82 | + if ($removeTrait){ |
|
| 83 | 83 | $tr = new NodeTraverser(); |
| 84 | 84 | $tr->addVisitor(new RemoveUse()); |
| 85 | 85 | $tr->addVisitor(new RemoveTrait()); |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | $tr = new NodeTraverser(); |
| 94 | 94 | $tr->addVisitor(new AddUse($node)); |
| 95 | 95 | |
| 96 | - if ($removeTrait) { |
|
| 96 | + if ($removeTrait){ |
|
| 97 | 97 | $tr->addVisitor(new RemoveUse()); |
| 98 | 98 | $tr->addVisitor(new RemoveTrait()); |
| 99 | 99 | } |
@@ -46,7 +46,8 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public function __construct(Lexer $lexer = null, PrettyPrinterAbstract $printer = null) |
| 48 | 48 | { |
| 49 | - if ($lexer === null) { |
|
| 49 | + if ($lexer === null) |
|
| 50 | + { |
|
| 50 | 51 | $lexer = new Emulative([ |
| 51 | 52 | 'usedAttributes' => [ |
| 52 | 53 | 'comments', |
@@ -78,8 +79,10 @@ discard block |
||
| 78 | 79 | bool $useTypedProperties = false, |
| 79 | 80 | bool $noPhpDoc = false |
| 80 | 81 | ): string { |
| 81 | - if (empty($node->dependencies)) { |
|
| 82 | - if ($removeTrait) { |
|
| 82 | + if (empty($node->dependencies)) |
|
| 83 | + { |
|
| 84 | + if ($removeTrait) |
|
| 85 | + { |
|
| 83 | 86 | $tr = new NodeTraverser(); |
| 84 | 87 | $tr->addVisitor(new RemoveUse()); |
| 85 | 88 | $tr->addVisitor(new RemoveTrait()); |
@@ -93,7 +96,8 @@ discard block |
||
| 93 | 96 | $tr = new NodeTraverser(); |
| 94 | 97 | $tr->addVisitor(new AddUse($node)); |
| 95 | 98 | |
| 96 | - if ($removeTrait) { |
|
| 99 | + if ($removeTrait) |
|
| 100 | + { |
|
| 97 | 101 | $tr->addVisitor(new RemoveUse()); |
| 98 | 102 | $tr->addVisitor(new RemoveTrait()); |
| 99 | 103 | } |
@@ -90,7 +90,8 @@ discard block |
||
| 90 | 90 | |
| 91 | 91 | $this->configureIO($input, $output); |
| 92 | 92 | |
| 93 | - if ($command !== null) { |
|
| 93 | + if ($command !== null) |
|
| 94 | + { |
|
| 94 | 95 | $input = new InputProxy($input, ['firstArgument' => $command]); |
| 95 | 96 | } |
| 96 | 97 | |
@@ -107,7 +108,8 @@ discard block |
||
| 107 | 108 | */ |
| 108 | 109 | public function getApplication(): Application |
| 109 | 110 | { |
| 110 | - if ($this->application !== null) { |
|
| 111 | + if ($this->application !== null) |
|
| 112 | + { |
|
| 111 | 113 | return $this->application; |
| 112 | 114 | } |
| 113 | 115 | |
@@ -115,7 +117,8 @@ discard block |
||
| 115 | 117 | $this->application->setCatchExceptions(false); |
| 116 | 118 | $this->application->setAutoExit(false); |
| 117 | 119 | |
| 118 | - if ($this->locator !== null) { |
|
| 120 | + if ($this->locator !== null) |
|
| 121 | + { |
|
| 119 | 122 | $this->addCommands($this->locator->locateCommands()); |
| 120 | 123 | } |
| 121 | 124 | |
@@ -128,8 +131,10 @@ discard block |
||
| 128 | 131 | |
| 129 | 132 | private function addCommands(iterable $commands): void |
| 130 | 133 | { |
| 131 | - foreach ($commands as $command) { |
|
| 132 | - if ($command instanceof Command) { |
|
| 134 | + foreach ($commands as $command) |
|
| 135 | + { |
|
| 136 | + if ($command instanceof Command) |
|
| 137 | + { |
|
| 133 | 138 | $command->setContainer($this->container); |
| 134 | 139 | } |
| 135 | 140 | |
@@ -144,27 +149,36 @@ discard block |
||
| 144 | 149 | */ |
| 145 | 150 | private function configureIO(InputInterface $input, OutputInterface $output): void |
| 146 | 151 | { |
| 147 | - if (true === $input->hasParameterOption(['--ansi'], true)) { |
|
| 152 | + if (true === $input->hasParameterOption(['--ansi'], true)) |
|
| 153 | + { |
|
| 148 | 154 | $output->setDecorated(true); |
| 149 | - } elseif (true === $input->hasParameterOption(['--no-ansi'], true)) { |
|
| 155 | + } |
|
| 156 | + elseif (true === $input->hasParameterOption(['--no-ansi'], true)) |
|
| 157 | + { |
|
| 150 | 158 | $output->setDecorated(false); |
| 151 | 159 | } |
| 152 | 160 | |
| 153 | - if (true === $input->hasParameterOption(['--no-interaction', '-n'], true)) { |
|
| 161 | + if (true === $input->hasParameterOption(['--no-interaction', '-n'], true)) |
|
| 162 | + { |
|
| 154 | 163 | $input->setInteractive(false); |
| 155 | - } elseif (\function_exists('posix_isatty')) { |
|
| 164 | + } |
|
| 165 | + elseif (\function_exists('posix_isatty')) |
|
| 166 | + { |
|
| 156 | 167 | $inputStream = null; |
| 157 | 168 | |
| 158 | - if ($input instanceof StreamableInputInterface) { |
|
| 169 | + if ($input instanceof StreamableInputInterface) |
|
| 170 | + { |
|
| 159 | 171 | $inputStream = $input->getStream(); |
| 160 | 172 | } |
| 161 | 173 | |
| 162 | - if (!@posix_isatty($inputStream) && false === getenv('SHELL_INTERACTIVE')) { |
|
| 174 | + if (!@posix_isatty($inputStream) && false === getenv('SHELL_INTERACTIVE')) |
|
| 175 | + { |
|
| 163 | 176 | $input->setInteractive(false); |
| 164 | 177 | } |
| 165 | 178 | } |
| 166 | 179 | |
| 167 | - switch ($shellVerbosity = (int)getenv('SHELL_VERBOSITY')) { |
|
| 180 | + switch ($shellVerbosity = (int)getenv('SHELL_VERBOSITY')) |
|
| 181 | + { |
|
| 168 | 182 | case -1: |
| 169 | 183 | $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); |
| 170 | 184 | break; |
@@ -187,7 +201,9 @@ discard block |
||
| 187 | 201 | ) { |
| 188 | 202 | $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); |
| 189 | 203 | $shellVerbosity = -1; |
| 190 | - } else { |
|
| 204 | + } |
|
| 205 | + else |
|
| 206 | + { |
|
| 191 | 207 | if ( |
| 192 | 208 | $input->hasParameterOption('-vvv', true) |
| 193 | 209 | || $input->hasParameterOption('--verbose=3', true) |
@@ -195,14 +211,16 @@ discard block |
||
| 195 | 211 | ) { |
| 196 | 212 | $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG); |
| 197 | 213 | $shellVerbosity = 3; |
| 198 | - } elseif ( |
|
| 214 | + } |
|
| 215 | + elseif ( |
|
| 199 | 216 | $input->hasParameterOption('-vv', true) |
| 200 | 217 | || $input->hasParameterOption('--verbose=2', true) |
| 201 | 218 | || 2 === $input->getParameterOption('--verbose', false, true) |
| 202 | 219 | ) { |
| 203 | 220 | $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); |
| 204 | 221 | $shellVerbosity = 2; |
| 205 | - } elseif ( |
|
| 222 | + } |
|
| 223 | + elseif ( |
|
| 206 | 224 | $input->hasParameterOption('-v', true) |
| 207 | 225 | || $input->hasParameterOption('--verbose=1', true) |
| 208 | 226 | || $input->hasParameterOption('--verbose', true) |
@@ -213,7 +231,8 @@ discard block |
||
| 213 | 231 | } |
| 214 | 232 | } |
| 215 | 233 | |
| 216 | - if (-1 === $shellVerbosity) { |
|
| 234 | + if (-1 === $shellVerbosity) |
|
| 235 | + { |
|
| 217 | 236 | $input->setInteractive(false); |
| 218 | 237 | } |
| 219 | 238 | |
@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | $schema = $this->constant('SCHEMA')->getValue(); |
| 50 | 50 | $validates = $this->constant('VALIDATES')->getValue(); |
| 51 | 51 | |
| 52 | - if (!isset($this->mapping[$type])) { |
|
| 53 | - $schema[$field] = ($source ?? self::DEFAULT_SOURCE) . ':' . ($origin ?: $field); |
|
| 52 | + if (!isset($this->mapping[$type])){ |
|
| 53 | + $schema[$field] = ($source ?? self::DEFAULT_SOURCE).':'.($origin ?: $field); |
|
| 54 | 54 | |
| 55 | 55 | $this->constant('SCHEMA')->setValue($schema); |
| 56 | 56 | |
@@ -61,9 +61,9 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | //Source can depend on type |
| 63 | 63 | $source ??= $definition['source']; |
| 64 | - $schema[$field] = $source . ':' . ($origin ?: $field); |
|
| 64 | + $schema[$field] = $source.':'.($origin ?: $field); |
|
| 65 | 65 | |
| 66 | - if (!empty($definition['validates'])) { |
|
| 66 | + if (!empty($definition['validates'])){ |
|
| 67 | 67 | //Pre-defined validation |
| 68 | 68 | $validates[$field] = $definition['validates']; |
| 69 | 69 | } |
@@ -49,7 +49,8 @@ discard block |
||
| 49 | 49 | $schema = $this->constant('SCHEMA')->getValue(); |
| 50 | 50 | $validates = $this->constant('VALIDATES')->getValue(); |
| 51 | 51 | |
| 52 | - if (!isset($this->mapping[$type])) { |
|
| 52 | + if (!isset($this->mapping[$type])) |
|
| 53 | + { |
|
| 53 | 54 | $schema[$field] = ($source ?? self::DEFAULT_SOURCE) . ':' . ($origin ?: $field); |
| 54 | 55 | |
| 55 | 56 | $this->constant('SCHEMA')->setValue($schema); |
@@ -63,7 +64,8 @@ discard block |
||
| 63 | 64 | $source ??= $definition['source']; |
| 64 | 65 | $schema[$field] = $source . ':' . ($origin ?: $field); |
| 65 | 66 | |
| 66 | - if (!empty($definition['validates'])) { |
|
| 67 | + if (!empty($definition['validates'])) |
|
| 68 | + { |
|
| 67 | 69 | //Pre-defined validation |
| 68 | 70 | $validates[$field] = $definition['validates']; |
| 69 | 71 | } |
@@ -76,9 +76,9 @@ discard block |
||
| 76 | 76 | $console->addCommand(MiddlewareCommand::class); |
| 77 | 77 | $console->addCommand(MigrationCommand::class, true); |
| 78 | 78 | |
| 79 | - try { |
|
| 79 | + try{ |
|
| 80 | 80 | $defaultNamespace = (new ReflectionClass($this->kernel))->getNamespaceName(); |
| 81 | - } catch (ReflectionException $e) { |
|
| 81 | + }catch (ReflectionException $e){ |
|
| 82 | 82 | $defaultNamespace = ''; |
| 83 | 83 | } |
| 84 | 84 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * Base directory for generated classes, class will be automatically localed into sub directory |
| 98 | 98 | * using given namespace. |
| 99 | 99 | */ |
| 100 | - 'directory' => directory('app') . 'src/', |
|
| 100 | + 'directory' => directory('app').'src/', |
|
| 101 | 101 | |
| 102 | 102 | /* |
| 103 | 103 | * Default namespace to be applied for every generated class. By default uses Kernel namespace |
@@ -76,9 +76,12 @@ |
||
| 76 | 76 | $console->addCommand(MiddlewareCommand::class); |
| 77 | 77 | $console->addCommand(MigrationCommand::class, true); |
| 78 | 78 | |
| 79 | - try { |
|
| 79 | + try |
|
| 80 | + { |
|
| 80 | 81 | $defaultNamespace = (new ReflectionClass($this->kernel))->getNamespaceName(); |
| 81 | - } catch (ReflectionException $e) { |
|
| 82 | + } |
|
| 83 | + catch (ReflectionException $e) |
|
| 84 | + { |
|
| 82 | 85 | $defaultNamespace = ''; |
| 83 | 86 | } |
| 84 | 87 | |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | public function __construct(array $config = []) |
| 35 | 35 | { |
| 36 | 36 | parent::__construct($config); |
| 37 | - if (!empty($this->config['aliases'])) { |
|
| 37 | + if (!empty($this->config['aliases'])){ |
|
| 38 | 38 | $this->config['aliases'] = $this->normalizeAliases($this->config['aliases']); |
| 39 | 39 | } |
| 40 | 40 | } |
@@ -50,12 +50,12 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | public function getChecker(string $name): Autowire |
| 52 | 52 | { |
| 53 | - if (!$this->hasChecker($name)) { |
|
| 53 | + if (!$this->hasChecker($name)){ |
|
| 54 | 54 | throw new ValidationException("Undefined checker `{$name}``."); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | $instance = $this->wire('checkers', $name); |
| 58 | - if ($instance !== null) { |
|
| 58 | + if ($instance !== null){ |
|
| 59 | 59 | return $instance; |
| 60 | 60 | } |
| 61 | 61 | |
@@ -69,12 +69,12 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | public function getCondition(string $name): Autowire |
| 71 | 71 | { |
| 72 | - if (!$this->hasCondition($name)) { |
|
| 72 | + if (!$this->hasCondition($name)){ |
|
| 73 | 73 | throw new ValidationException("Undefined condition `{$name}`."); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | $instance = $this->wire('conditions', $name); |
| 77 | - if ($instance !== null) { |
|
| 77 | + if ($instance !== null){ |
|
| 78 | 78 | return $instance; |
| 79 | 79 | } |
| 80 | 80 | |
@@ -90,9 +90,9 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | public function mapFunction($function) |
| 92 | 92 | { |
| 93 | - if (is_string($function)) { |
|
| 93 | + if (is_string($function)){ |
|
| 94 | 94 | $function = $this->resolveAlias($function); |
| 95 | - if (strpos($function, ':') !== false) { |
|
| 95 | + if (strpos($function, ':') !== false){ |
|
| 96 | 96 | $function = explode(':', $function); |
| 97 | 97 | } |
| 98 | 98 | } |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | private function wire(string $section, string $name): ?Autowire |
| 104 | 104 | { |
| 105 | - if (is_string($this->config[$section][$name])) { |
|
| 105 | + if (is_string($this->config[$section][$name])){ |
|
| 106 | 106 | return new Autowire($this->config[$section][$name]); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - if (isset($this->config[$section][$name]['class'])) { |
|
| 109 | + if (isset($this->config[$section][$name]['class'])){ |
|
| 110 | 110 | return new Autowire( |
| 111 | 111 | $this->config[$section][$name]['class'], |
| 112 | 112 | $this->config[$section][$name]['options'] ?? [] |
@@ -34,7 +34,8 @@ discard block |
||
| 34 | 34 | public function __construct(array $config = []) |
| 35 | 35 | { |
| 36 | 36 | parent::__construct($config); |
| 37 | - if (!empty($this->config['aliases'])) { |
|
| 37 | + if (!empty($this->config['aliases'])) |
|
| 38 | + { |
|
| 38 | 39 | $this->config['aliases'] = $this->normalizeAliases($this->config['aliases']); |
| 39 | 40 | } |
| 40 | 41 | } |
@@ -50,12 +51,14 @@ discard block |
||
| 50 | 51 | */ |
| 51 | 52 | public function getChecker(string $name): Autowire |
| 52 | 53 | { |
| 53 | - if (!$this->hasChecker($name)) { |
|
| 54 | + if (!$this->hasChecker($name)) |
|
| 55 | + { |
|
| 54 | 56 | throw new ValidationException("Undefined checker `{$name}``."); |
| 55 | 57 | } |
| 56 | 58 | |
| 57 | 59 | $instance = $this->wire('checkers', $name); |
| 58 | - if ($instance !== null) { |
|
| 60 | + if ($instance !== null) |
|
| 61 | + { |
|
| 59 | 62 | return $instance; |
| 60 | 63 | } |
| 61 | 64 | |
@@ -69,12 +72,14 @@ discard block |
||
| 69 | 72 | |
| 70 | 73 | public function getCondition(string $name): Autowire |
| 71 | 74 | { |
| 72 | - if (!$this->hasCondition($name)) { |
|
| 75 | + if (!$this->hasCondition($name)) |
|
| 76 | + { |
|
| 73 | 77 | throw new ValidationException("Undefined condition `{$name}`."); |
| 74 | 78 | } |
| 75 | 79 | |
| 76 | 80 | $instance = $this->wire('conditions', $name); |
| 77 | - if ($instance !== null) { |
|
| 81 | + if ($instance !== null) |
|
| 82 | + { |
|
| 78 | 83 | return $instance; |
| 79 | 84 | } |
| 80 | 85 | |
@@ -90,9 +95,11 @@ discard block |
||
| 90 | 95 | */ |
| 91 | 96 | public function mapFunction($function) |
| 92 | 97 | { |
| 93 | - if (is_string($function)) { |
|
| 98 | + if (is_string($function)) |
|
| 99 | + { |
|
| 94 | 100 | $function = $this->resolveAlias($function); |
| 95 | - if (strpos($function, ':') !== false) { |
|
| 101 | + if (strpos($function, ':') !== false) |
|
| 102 | + { |
|
| 96 | 103 | $function = explode(':', $function); |
| 97 | 104 | } |
| 98 | 105 | } |
@@ -102,11 +109,13 @@ discard block |
||
| 102 | 109 | |
| 103 | 110 | private function wire(string $section, string $name): ?Autowire |
| 104 | 111 | { |
| 105 | - if (is_string($this->config[$section][$name])) { |
|
| 112 | + if (is_string($this->config[$section][$name])) |
|
| 113 | + { |
|
| 106 | 114 | return new Autowire($this->config[$section][$name]); |
| 107 | 115 | } |
| 108 | 116 | |
| 109 | - if (isset($this->config[$section][$name]['class'])) { |
|
| 117 | + if (isset($this->config[$section][$name]['class'])) |
|
| 118 | + { |
|
| 110 | 119 | return new Autowire( |
| 111 | 120 | $this->config[$section][$name]['class'], |
| 112 | 121 | $this->config[$section][$name]['options'] ?? [] |
@@ -58,11 +58,11 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | private function validateBoundaries(Boundary $from, Boundary $to): void |
| 60 | 60 | { |
| 61 | - if (!$this->acceptsBoundary($from) || !$this->acceptsBoundary($to)) { |
|
| 61 | + if (!$this->acceptsBoundary($from) || !$this->acceptsBoundary($to)){ |
|
| 62 | 62 | throw new ValueException('Range boundaries should be applicable via passed type.'); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - if ($this->convertBoundaryValue($from) === $this->convertBoundaryValue($to)) { |
|
| 65 | + if ($this->convertBoundaryValue($from) === $this->convertBoundaryValue($to)){ |
|
| 66 | 66 | throw new ValueException('Range boundaries should be different.'); |
| 67 | 67 | } |
| 68 | 68 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | private function acceptsFrom($value): bool |
| 87 | 87 | { |
| 88 | - if ($this->from->empty) { |
|
| 88 | + if ($this->from->empty){ |
|
| 89 | 89 | return true; |
| 90 | 90 | } |
| 91 | 91 | |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | private function acceptsTo($value): bool |
| 101 | 101 | { |
| 102 | - if ($this->to->empty) { |
|
| 102 | + if ($this->to->empty){ |
|
| 103 | 103 | return true; |
| 104 | 104 | } |
| 105 | 105 | |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | private function setBoundaries(Boundary $from, Boundary $to): void |
| 112 | 112 | { |
| 113 | 113 | //Swap if from < to and both not empty |
| 114 | - if (!$from->empty && !$to->empty && $from->value > $to->value) { |
|
| 114 | + if (!$from->empty && !$to->empty && $from->value > $to->value){ |
|
| 115 | 115 | [$from, $to] = [$to, $from]; |
| 116 | 116 | } |
| 117 | 117 | |
@@ -58,11 +58,13 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | private function validateBoundaries(Boundary $from, Boundary $to): void |
| 60 | 60 | { |
| 61 | - if (!$this->acceptsBoundary($from) || !$this->acceptsBoundary($to)) { |
|
| 61 | + if (!$this->acceptsBoundary($from) || !$this->acceptsBoundary($to)) |
|
| 62 | + { |
|
| 62 | 63 | throw new ValueException('Range boundaries should be applicable via passed type.'); |
| 63 | 64 | } |
| 64 | 65 | |
| 65 | - if ($this->convertBoundaryValue($from) === $this->convertBoundaryValue($to)) { |
|
| 66 | + if ($this->convertBoundaryValue($from) === $this->convertBoundaryValue($to)) |
|
| 67 | + { |
|
| 66 | 68 | throw new ValueException('Range boundaries should be different.'); |
| 67 | 69 | } |
| 68 | 70 | } |
@@ -85,7 +87,8 @@ discard block |
||
| 85 | 87 | */ |
| 86 | 88 | private function acceptsFrom($value): bool |
| 87 | 89 | { |
| 88 | - if ($this->from->empty) { |
|
| 90 | + if ($this->from->empty) |
|
| 91 | + { |
|
| 89 | 92 | return true; |
| 90 | 93 | } |
| 91 | 94 | |
@@ -99,7 +102,8 @@ discard block |
||
| 99 | 102 | */ |
| 100 | 103 | private function acceptsTo($value): bool |
| 101 | 104 | { |
| 102 | - if ($this->to->empty) { |
|
| 105 | + if ($this->to->empty) |
|
| 106 | + { |
|
| 103 | 107 | return true; |
| 104 | 108 | } |
| 105 | 109 | |
@@ -111,7 +115,8 @@ discard block |
||
| 111 | 115 | private function setBoundaries(Boundary $from, Boundary $to): void |
| 112 | 116 | { |
| 113 | 117 | //Swap if from < to and both not empty |
| 114 | - if (!$from->empty && !$to->empty && $from->value > $to->value) { |
|
| 118 | + if (!$from->empty && !$to->empty && $from->value > $to->value) |
|
| 119 | + { |
|
| 115 | 120 | [$from, $to] = [$to, $from]; |
| 116 | 121 | } |
| 117 | 122 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function __construct(array $items = []) |
| 37 | 37 | { |
| 38 | - foreach ($items as $item) { |
|
| 38 | + foreach ($items as $item){ |
|
| 39 | 39 | $this->addItem($item); |
| 40 | 40 | } |
| 41 | 41 | } |
@@ -50,9 +50,9 @@ discard block |
||
| 50 | 50 | $header = new static(); |
| 51 | 51 | |
| 52 | 52 | $parts = explode(',', $raw); |
| 53 | - foreach ($parts as $part) { |
|
| 53 | + foreach ($parts as $part){ |
|
| 54 | 54 | $part = trim($part); |
| 55 | - if ($part !== '') { |
|
| 55 | + if ($part !== ''){ |
|
| 56 | 56 | $header->addItem($part); |
| 57 | 57 | } |
| 58 | 58 | } |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | public function getAll(): array |
| 88 | 88 | { |
| 89 | - if (!$this->sorted) { |
|
| 89 | + if (!$this->sorted){ |
|
| 90 | 90 | /** |
| 91 | 91 | * Sort item in descending order. |
| 92 | 92 | */ |
@@ -105,12 +105,12 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | private function addItem($item): void |
| 107 | 107 | { |
| 108 | - if (is_scalar($item)) { |
|
| 108 | + if (is_scalar($item)){ |
|
| 109 | 109 | $item = AcceptHeaderItem::fromString((string)$item); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** @var AcceptHeaderItem|array $item */ |
| 113 | - if (!$item instanceof AcceptHeaderItem) { |
|
| 113 | + if (!$item instanceof AcceptHeaderItem){ |
|
| 114 | 114 | throw new AcceptHeaderException(sprintf( |
| 115 | 115 | 'Accept Header item expected to be an instance of `%s` or a string, got `%s`', |
| 116 | 116 | AcceptHeaderItem::class, |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | $value = strtolower($item->getValue()); |
| 122 | - if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) { |
|
| 122 | + if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)){ |
|
| 123 | 123 | $this->sorted = false; |
| 124 | 124 | $this->items[$value] = $item; |
| 125 | 125 | } |
@@ -134,9 +134,9 @@ discard block |
||
| 134 | 134 | */ |
| 135 | 135 | private static function compare(AcceptHeaderItem $a, AcceptHeaderItem $b): int |
| 136 | 136 | { |
| 137 | - if ($a->getQuality() === $b->getQuality()) { |
|
| 137 | + if ($a->getQuality() === $b->getQuality()){ |
|
| 138 | 138 | // If quality are same value with more params has more weight. |
| 139 | - if (count($a->getParams()) === count($b->getParams())) { |
|
| 139 | + if (count($a->getParams()) === count($b->getParams())){ |
|
| 140 | 140 | // If quality and params then check for specific type or subtype. |
| 141 | 141 | // Means */* or * has less weight. |
| 142 | 142 | return static::compareValue($a->getValue(), $b->getValue()); |
@@ -155,11 +155,11 @@ discard block |
||
| 155 | 155 | private static function compareValue(string $a, string $b): int |
| 156 | 156 | { |
| 157 | 157 | // Check "Accept" headers values with it is type and subtype. |
| 158 | - if (strpos($a, '/') !== false && strpos($b, '/') !== false) { |
|
| 158 | + if (strpos($a, '/') !== false && strpos($b, '/') !== false){ |
|
| 159 | 159 | [$typeA, $subtypeA] = explode('/', $a, 2); |
| 160 | 160 | [$typeB, $subtypeB] = explode('/', $b, 2); |
| 161 | 161 | |
| 162 | - if ($typeA === $typeB) { |
|
| 162 | + if ($typeA === $typeB){ |
|
| 163 | 163 | return static::compareAtomic($subtypeA, $subtypeB); |
| 164 | 164 | } |
| 165 | 165 | |
@@ -171,23 +171,23 @@ discard block |
||
| 171 | 171 | |
| 172 | 172 | private static function compareAtomic(string $a, string $b): int |
| 173 | 173 | { |
| 174 | - if (mb_strpos($a, '*/') === 0) { |
|
| 174 | + if (mb_strpos($a, '*/') === 0){ |
|
| 175 | 175 | $a = '*'; |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - if (mb_strpos($b, '*/') === 0) { |
|
| 178 | + if (mb_strpos($b, '*/') === 0){ |
|
| 179 | 179 | $b = '*'; |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - if (strtolower($a) === strtolower($b)) { |
|
| 182 | + if (strtolower($a) === strtolower($b)){ |
|
| 183 | 183 | return 0; |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - if ($a === '*') { |
|
| 186 | + if ($a === '*'){ |
|
| 187 | 187 | return -1; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - if ($b === '*') { |
|
| 190 | + if ($b === '*'){ |
|
| 191 | 191 | return 1; |
| 192 | 192 | } |
| 193 | 193 | |
@@ -35,7 +35,8 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function __construct(array $items = []) |
| 37 | 37 | { |
| 38 | - foreach ($items as $item) { |
|
| 38 | + foreach ($items as $item) |
|
| 39 | + { |
|
| 39 | 40 | $this->addItem($item); |
| 40 | 41 | } |
| 41 | 42 | } |
@@ -50,9 +51,11 @@ discard block |
||
| 50 | 51 | $header = new static(); |
| 51 | 52 | |
| 52 | 53 | $parts = explode(',', $raw); |
| 53 | - foreach ($parts as $part) { |
|
| 54 | + foreach ($parts as $part) |
|
| 55 | + { |
|
| 54 | 56 | $part = trim($part); |
| 55 | - if ($part !== '') { |
|
| 57 | + if ($part !== '') |
|
| 58 | + { |
|
| 56 | 59 | $header->addItem($part); |
| 57 | 60 | } |
| 58 | 61 | } |
@@ -86,7 +89,8 @@ discard block |
||
| 86 | 89 | */ |
| 87 | 90 | public function getAll(): array |
| 88 | 91 | { |
| 89 | - if (!$this->sorted) { |
|
| 92 | + if (!$this->sorted) |
|
| 93 | + { |
|
| 90 | 94 | /** |
| 91 | 95 | * Sort item in descending order. |
| 92 | 96 | */ |
@@ -105,12 +109,14 @@ discard block |
||
| 105 | 109 | */ |
| 106 | 110 | private function addItem($item): void |
| 107 | 111 | { |
| 108 | - if (is_scalar($item)) { |
|
| 112 | + if (is_scalar($item)) |
|
| 113 | + { |
|
| 109 | 114 | $item = AcceptHeaderItem::fromString((string)$item); |
| 110 | 115 | } |
| 111 | 116 | |
| 112 | 117 | /** @var AcceptHeaderItem|array $item */ |
| 113 | - if (!$item instanceof AcceptHeaderItem) { |
|
| 118 | + if (!$item instanceof AcceptHeaderItem) |
|
| 119 | + { |
|
| 114 | 120 | throw new AcceptHeaderException(sprintf( |
| 115 | 121 | 'Accept Header item expected to be an instance of `%s` or a string, got `%s`', |
| 116 | 122 | AcceptHeaderItem::class, |
@@ -119,7 +125,8 @@ discard block |
||
| 119 | 125 | } |
| 120 | 126 | |
| 121 | 127 | $value = strtolower($item->getValue()); |
| 122 | - if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) { |
|
| 128 | + if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) |
|
| 129 | + { |
|
| 123 | 130 | $this->sorted = false; |
| 124 | 131 | $this->items[$value] = $item; |
| 125 | 132 | } |
@@ -134,9 +141,11 @@ discard block |
||
| 134 | 141 | */ |
| 135 | 142 | private static function compare(AcceptHeaderItem $a, AcceptHeaderItem $b): int |
| 136 | 143 | { |
| 137 | - if ($a->getQuality() === $b->getQuality()) { |
|
| 144 | + if ($a->getQuality() === $b->getQuality()) |
|
| 145 | + { |
|
| 138 | 146 | // If quality are same value with more params has more weight. |
| 139 | - if (count($a->getParams()) === count($b->getParams())) { |
|
| 147 | + if (count($a->getParams()) === count($b->getParams())) |
|
| 148 | + { |
|
| 140 | 149 | // If quality and params then check for specific type or subtype. |
| 141 | 150 | // Means */* or * has less weight. |
| 142 | 151 | return static::compareValue($a->getValue(), $b->getValue()); |
@@ -155,11 +164,13 @@ discard block |
||
| 155 | 164 | private static function compareValue(string $a, string $b): int |
| 156 | 165 | { |
| 157 | 166 | // Check "Accept" headers values with it is type and subtype. |
| 158 | - if (strpos($a, '/') !== false && strpos($b, '/') !== false) { |
|
| 167 | + if (strpos($a, '/') !== false && strpos($b, '/') !== false) |
|
| 168 | + { |
|
| 159 | 169 | [$typeA, $subtypeA] = explode('/', $a, 2); |
| 160 | 170 | [$typeB, $subtypeB] = explode('/', $b, 2); |
| 161 | 171 | |
| 162 | - if ($typeA === $typeB) { |
|
| 172 | + if ($typeA === $typeB) |
|
| 173 | + { |
|
| 163 | 174 | return static::compareAtomic($subtypeA, $subtypeB); |
| 164 | 175 | } |
| 165 | 176 | |
@@ -171,23 +182,28 @@ discard block |
||
| 171 | 182 | |
| 172 | 183 | private static function compareAtomic(string $a, string $b): int |
| 173 | 184 | { |
| 174 | - if (mb_strpos($a, '*/') === 0) { |
|
| 185 | + if (mb_strpos($a, '*/') === 0) |
|
| 186 | + { |
|
| 175 | 187 | $a = '*'; |
| 176 | 188 | } |
| 177 | 189 | |
| 178 | - if (mb_strpos($b, '*/') === 0) { |
|
| 190 | + if (mb_strpos($b, '*/') === 0) |
|
| 191 | + { |
|
| 179 | 192 | $b = '*'; |
| 180 | 193 | } |
| 181 | 194 | |
| 182 | - if (strtolower($a) === strtolower($b)) { |
|
| 195 | + if (strtolower($a) === strtolower($b)) |
|
| 196 | + { |
|
| 183 | 197 | return 0; |
| 184 | 198 | } |
| 185 | 199 | |
| 186 | - if ($a === '*') { |
|
| 200 | + if ($a === '*') |
|
| 201 | + { |
|
| 187 | 202 | return -1; |
| 188 | 203 | } |
| 189 | 204 | |
| 190 | - if ($b === '*') { |
|
| 205 | + if ($b === '*') |
|
| 206 | + { |
|
| 191 | 207 | return 1; |
| 192 | 208 | } |
| 193 | 209 | |
@@ -65,12 +65,14 @@ |
||
| 65 | 65 | */ |
| 66 | 66 | public function handle(Request $request): Response |
| 67 | 67 | { |
| 68 | - if (empty($this->handler)) { |
|
| 68 | + if (empty($this->handler)) |
|
| 69 | + { |
|
| 69 | 70 | throw new PipelineException('Unable to run pipeline, no handler given.'); |
| 70 | 71 | } |
| 71 | 72 | |
| 72 | 73 | $position = $this->position++; |
| 73 | - if (isset($this->middleware[$position])) { |
|
| 74 | + if (isset($this->middleware[$position])) |
|
| 75 | + { |
|
| 74 | 76 | return $this->middleware[$position]->process($request, $this); |
| 75 | 77 | } |
| 76 | 78 | |