@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | $exceptions = [$exception]; |
| 67 | 67 | $currentE = $exception; |
| 68 | 68 | |
| 69 | - while ($exception = $exception->getPrevious()) { |
|
| 69 | + while ($exception = $exception->getPrevious()){ |
|
| 70 | 70 | $exceptions[] = $exception; |
| 71 | 71 | } |
| 72 | 72 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | $result = []; |
| 76 | 76 | $rootDir = \getcwd(); |
| 77 | 77 | |
| 78 | - foreach ($exceptions as $exception) { |
|
| 78 | + foreach ($exceptions as $exception){ |
|
| 79 | 79 | $prefix = $currentE === $exception ? '' : 'Previous: '; |
| 80 | 80 | $row = $this->renderHeader( |
| 81 | 81 | \sprintf("%s[%s]\n%s", $prefix, $exception::class, $exception->getMessage()), |
@@ -92,14 +92,14 @@ discard block |
||
| 92 | 92 | $exception->getLine(), |
| 93 | 93 | ); |
| 94 | 94 | |
| 95 | - if ($verbosity->value >= Verbosity::DEBUG->value) { |
|
| 95 | + if ($verbosity->value >= Verbosity::DEBUG->value){ |
|
| 96 | 96 | $row .= $this->renderTrace( |
| 97 | 97 | $exception, |
| 98 | 98 | new Highlighter( |
| 99 | 99 | $this->colorsSupport ? new ConsoleStyle() : new PlainStyle(), |
| 100 | 100 | ), |
| 101 | 101 | ); |
| 102 | - } elseif ($verbosity->value >= Verbosity::VERBOSE->value) { |
|
| 102 | + } elseif ($verbosity->value >= Verbosity::VERBOSE->value){ |
|
| 103 | 103 | $row .= $this->renderTrace($exception); |
| 104 | 104 | } |
| 105 | 105 | |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | |
| 131 | 131 | $length += $padding; |
| 132 | 132 | |
| 133 | - foreach ($lines as $line) { |
|
| 133 | + foreach ($lines as $line){ |
|
| 134 | 134 | $result .= $this->format( |
| 135 | 135 | "<{$style}>%s%s%s</reset>\n", |
| 136 | 136 | \str_repeat('', $padding + 1), |
@@ -148,39 +148,39 @@ discard block |
||
| 148 | 148 | private function renderTrace(\Throwable $e, ?Highlighter $h = null): string |
| 149 | 149 | { |
| 150 | 150 | $stacktrace = $this->getStacktrace($e); |
| 151 | - if (empty($stacktrace)) { |
|
| 151 | + if (empty($stacktrace)){ |
|
| 152 | 152 | return ''; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | $result = "\n"; |
| 156 | 156 | $rootDir = \getcwd(); |
| 157 | 157 | |
| 158 | - $pad = \strlen((string) \count($stacktrace)); |
|
| 158 | + $pad = \strlen((string)\count($stacktrace)); |
|
| 159 | 159 | |
| 160 | - foreach ($stacktrace as $i => $trace) { |
|
| 161 | - $file = isset($trace['file']) ? (string) $trace['file'] : null; |
|
| 160 | + foreach ($stacktrace as $i => $trace){ |
|
| 161 | + $file = isset($trace['file']) ? (string)$trace['file'] : null; |
|
| 162 | 162 | $classColor = 'while'; |
| 163 | 163 | |
| 164 | - if ($file !== null) { |
|
| 164 | + if ($file !== null){ |
|
| 165 | 165 | \str_starts_with($file, $rootDir) and $file = \substr($file, \strlen($rootDir) + 1); |
| 166 | 166 | $classColor = \str_starts_with($file, 'vendor/') ? 'gray' : 'white'; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - if (isset($trace['type'], $trace['class'])) { |
|
| 169 | + if (isset($trace['type'], $trace['class'])){ |
|
| 170 | 170 | $line = $this->format( |
| 171 | 171 | "<$classColor>%s.</reset> <white>%s%s%s()</reset>", |
| 172 | - \str_pad((string) ((int) $i + 1), $pad, ' ', \STR_PAD_LEFT), |
|
| 172 | + \str_pad((string)((int)$i + 1), $pad, ' ', \STR_PAD_LEFT), |
|
| 173 | 173 | $trace['class'], |
| 174 | 174 | $trace['type'], |
| 175 | 175 | $trace['function'], |
| 176 | 176 | ); |
| 177 | - } else { |
|
| 177 | + }else{ |
|
| 178 | 178 | $line = $this->format( |
| 179 | 179 | ' <white>%s()</reset>', |
| 180 | 180 | $trace['function'], |
| 181 | 181 | ); |
| 182 | 182 | } |
| 183 | - if ($file !== null) { |
|
| 183 | + if ($file !== null){ |
|
| 184 | 184 | $line .= $this->format( |
| 185 | 185 | ' <yellow>at</reset> <green>%s</reset><yellow>:</reset><white>%s</reset>', |
| 186 | 186 | $file, |
@@ -188,21 +188,21 @@ discard block |
||
| 188 | 188 | ); |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - if (\in_array($line, $this->lines, true)) { |
|
| 191 | + if (\in_array($line, $this->lines, true)){ |
|
| 192 | 192 | continue; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | $this->lines[] = $line; |
| 196 | 196 | |
| 197 | - $result .= $line . "\n"; |
|
| 197 | + $result .= $line."\n"; |
|
| 198 | 198 | |
| 199 | - if ($h !== null && !empty($trace['file'])) { |
|
| 199 | + if ($h !== null && !empty($trace['file'])){ |
|
| 200 | 200 | $str = @\file_get_contents($trace['file']); |
| 201 | 201 | $result .= $h->highlightLines( |
| 202 | 202 | $str, |
| 203 | 203 | $trace['line'], |
| 204 | 204 | static::SHOW_LINES, |
| 205 | - ) . "\n"; |
|
| 205 | + )."\n"; |
|
| 206 | 206 | unset($str); |
| 207 | 207 | } |
| 208 | 208 | } |
@@ -215,13 +215,13 @@ discard block |
||
| 215 | 215 | */ |
| 216 | 216 | private function format(string $format, mixed ...$args): string |
| 217 | 217 | { |
| 218 | - if (!$this->colorsSupport) { |
|
| 218 | + if (!$this->colorsSupport){ |
|
| 219 | 219 | $format = \preg_replace('/<[^>]+>/', '', $format); |
| 220 | - } else { |
|
| 221 | - $format = \preg_replace_callback('/(<([^>]+)>)/', static function ($partial) { |
|
| 220 | + }else{ |
|
| 221 | + $format = \preg_replace_callback('/(<([^>]+)>)/', static function ($partial){ |
|
| 222 | 222 | $style = ''; |
| 223 | - foreach (\explode(',', \trim($partial[2], '/')) as $color) { |
|
| 224 | - if (isset(self::COLORS[$color])) { |
|
| 223 | + foreach (\explode(',', \trim($partial[2], '/')) as $color){ |
|
| 224 | + if (isset(self::COLORS[$color])){ |
|
| 225 | 225 | $style .= self::COLORS[$color]; |
| 226 | 226 | } |
| 227 | 227 | } |
@@ -240,12 +240,12 @@ discard block |
||
| 240 | 240 | */ |
| 241 | 241 | private function isColorsSupported(mixed $stream = STDOUT): bool |
| 242 | 242 | { |
| 243 | - if (\getenv('TERM_PROGRAM') === 'Hyper') { |
|
| 243 | + if (\getenv('TERM_PROGRAM') === 'Hyper'){ |
|
| 244 | 244 | return true; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - try { |
|
| 248 | - if (\DIRECTORY_SEPARATOR === '\\') { |
|
| 247 | + try{ |
|
| 248 | + if (\DIRECTORY_SEPARATOR === '\\'){ |
|
| 249 | 249 | return (\function_exists('sapi_windows_vt100_support') && @\sapi_windows_vt100_support($stream)) |
| 250 | 250 | || \getenv('ANSICON') !== false |
| 251 | 251 | || \getenv('ConEmuANSI') === 'ON' |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | return @\stream_isatty($stream); |
| 256 | - } catch (\Throwable) { |
|
| 256 | + }catch (\Throwable){ |
|
| 257 | 257 | return false; |
| 258 | 258 | } |
| 259 | 259 | } |
@@ -66,7 +66,8 @@ discard block |
||
| 66 | 66 | $exceptions = [$exception]; |
| 67 | 67 | $currentE = $exception; |
| 68 | 68 | |
| 69 | - while ($exception = $exception->getPrevious()) { |
|
| 69 | + while ($exception = $exception->getPrevious()) |
|
| 70 | + { |
|
| 70 | 71 | $exceptions[] = $exception; |
| 71 | 72 | } |
| 72 | 73 | |
@@ -75,7 +76,8 @@ discard block |
||
| 75 | 76 | $result = []; |
| 76 | 77 | $rootDir = \getcwd(); |
| 77 | 78 | |
| 78 | - foreach ($exceptions as $exception) { |
|
| 79 | + foreach ($exceptions as $exception) |
|
| 80 | + { |
|
| 79 | 81 | $prefix = $currentE === $exception ? '' : 'Previous: '; |
| 80 | 82 | $row = $this->renderHeader( |
| 81 | 83 | \sprintf("%s[%s]\n%s", $prefix, $exception::class, $exception->getMessage()), |
@@ -92,14 +94,17 @@ discard block |
||
| 92 | 94 | $exception->getLine(), |
| 93 | 95 | ); |
| 94 | 96 | |
| 95 | - if ($verbosity->value >= Verbosity::DEBUG->value) { |
|
| 97 | + if ($verbosity->value >= Verbosity::DEBUG->value) |
|
| 98 | + { |
|
| 96 | 99 | $row .= $this->renderTrace( |
| 97 | 100 | $exception, |
| 98 | 101 | new Highlighter( |
| 99 | 102 | $this->colorsSupport ? new ConsoleStyle() : new PlainStyle(), |
| 100 | 103 | ), |
| 101 | 104 | ); |
| 102 | - } elseif ($verbosity->value >= Verbosity::VERBOSE->value) { |
|
| 105 | + } |
|
| 106 | + elseif ($verbosity->value >= Verbosity::VERBOSE->value) |
|
| 107 | + { |
|
| 103 | 108 | $row .= $this->renderTrace($exception); |
| 104 | 109 | } |
| 105 | 110 | |
@@ -130,7 +135,8 @@ discard block |
||
| 130 | 135 | |
| 131 | 136 | $length += $padding; |
| 132 | 137 | |
| 133 | - foreach ($lines as $line) { |
|
| 138 | + foreach ($lines as $line) |
|
| 139 | + { |
|
| 134 | 140 | $result .= $this->format( |
| 135 | 141 | "<{$style}>%s%s%s</reset>\n", |
| 136 | 142 | \str_repeat('', $padding + 1), |
@@ -148,7 +154,8 @@ discard block |
||
| 148 | 154 | private function renderTrace(\Throwable $e, ?Highlighter $h = null): string |
| 149 | 155 | { |
| 150 | 156 | $stacktrace = $this->getStacktrace($e); |
| 151 | - if (empty($stacktrace)) { |
|
| 157 | + if (empty($stacktrace)) |
|
| 158 | + { |
|
| 152 | 159 | return ''; |
| 153 | 160 | } |
| 154 | 161 | |
@@ -157,16 +164,19 @@ discard block |
||
| 157 | 164 | |
| 158 | 165 | $pad = \strlen((string) \count($stacktrace)); |
| 159 | 166 | |
| 160 | - foreach ($stacktrace as $i => $trace) { |
|
| 167 | + foreach ($stacktrace as $i => $trace) |
|
| 168 | + { |
|
| 161 | 169 | $file = isset($trace['file']) ? (string) $trace['file'] : null; |
| 162 | 170 | $classColor = 'while'; |
| 163 | 171 | |
| 164 | - if ($file !== null) { |
|
| 172 | + if ($file !== null) |
|
| 173 | + { |
|
| 165 | 174 | \str_starts_with($file, $rootDir) and $file = \substr($file, \strlen($rootDir) + 1); |
| 166 | 175 | $classColor = \str_starts_with($file, 'vendor/') ? 'gray' : 'white'; |
| 167 | 176 | } |
| 168 | 177 | |
| 169 | - if (isset($trace['type'], $trace['class'])) { |
|
| 178 | + if (isset($trace['type'], $trace['class'])) |
|
| 179 | + { |
|
| 170 | 180 | $line = $this->format( |
| 171 | 181 | "<$classColor>%s.</reset> <white>%s%s%s()</reset>", |
| 172 | 182 | \str_pad((string) ((int) $i + 1), $pad, ' ', \STR_PAD_LEFT), |
@@ -174,13 +184,16 @@ discard block |
||
| 174 | 184 | $trace['type'], |
| 175 | 185 | $trace['function'], |
| 176 | 186 | ); |
| 177 | - } else { |
|
| 187 | + } |
|
| 188 | + else |
|
| 189 | + { |
|
| 178 | 190 | $line = $this->format( |
| 179 | 191 | ' <white>%s()</reset>', |
| 180 | 192 | $trace['function'], |
| 181 | 193 | ); |
| 182 | 194 | } |
| 183 | - if ($file !== null) { |
|
| 195 | + if ($file !== null) |
|
| 196 | + { |
|
| 184 | 197 | $line .= $this->format( |
| 185 | 198 | ' <yellow>at</reset> <green>%s</reset><yellow>:</reset><white>%s</reset>', |
| 186 | 199 | $file, |
@@ -188,7 +201,8 @@ discard block |
||
| 188 | 201 | ); |
| 189 | 202 | } |
| 190 | 203 | |
| 191 | - if (\in_array($line, $this->lines, true)) { |
|
| 204 | + if (\in_array($line, $this->lines, true)) |
|
| 205 | + { |
|
| 192 | 206 | continue; |
| 193 | 207 | } |
| 194 | 208 | |
@@ -196,7 +210,8 @@ discard block |
||
| 196 | 210 | |
| 197 | 211 | $result .= $line . "\n"; |
| 198 | 212 | |
| 199 | - if ($h !== null && !empty($trace['file'])) { |
|
| 213 | + if ($h !== null && !empty($trace['file'])) |
|
| 214 | + { |
|
| 200 | 215 | $str = @\file_get_contents($trace['file']); |
| 201 | 216 | $result .= $h->highlightLines( |
| 202 | 217 | $str, |
@@ -215,13 +230,19 @@ discard block |
||
| 215 | 230 | */ |
| 216 | 231 | private function format(string $format, mixed ...$args): string |
| 217 | 232 | { |
| 218 | - if (!$this->colorsSupport) { |
|
| 233 | + if (!$this->colorsSupport) |
|
| 234 | + { |
|
| 219 | 235 | $format = \preg_replace('/<[^>]+>/', '', $format); |
| 220 | - } else { |
|
| 221 | - $format = \preg_replace_callback('/(<([^>]+)>)/', static function ($partial) { |
|
| 236 | + } |
|
| 237 | + else |
|
| 238 | + { |
|
| 239 | + $format = \preg_replace_callback('/(<([^>]+)>)/', static function ($partial) |
|
| 240 | + { |
|
| 222 | 241 | $style = ''; |
| 223 | - foreach (\explode(',', \trim($partial[2], '/')) as $color) { |
|
| 224 | - if (isset(self::COLORS[$color])) { |
|
| 242 | + foreach (\explode(',', \trim($partial[2], '/')) as $color) |
|
| 243 | + { |
|
| 244 | + if (isset(self::COLORS[$color])) |
|
| 245 | + { |
|
| 225 | 246 | $style .= self::COLORS[$color]; |
| 226 | 247 | } |
| 227 | 248 | } |
@@ -240,12 +261,15 @@ discard block |
||
| 240 | 261 | */ |
| 241 | 262 | private function isColorsSupported(mixed $stream = STDOUT): bool |
| 242 | 263 | { |
| 243 | - if (\getenv('TERM_PROGRAM') === 'Hyper') { |
|
| 264 | + if (\getenv('TERM_PROGRAM') === 'Hyper') |
|
| 265 | + { |
|
| 244 | 266 | return true; |
| 245 | 267 | } |
| 246 | 268 | |
| 247 | - try { |
|
| 248 | - if (\DIRECTORY_SEPARATOR === '\\') { |
|
| 269 | + try |
|
| 270 | + { |
|
| 271 | + if (\DIRECTORY_SEPARATOR === '\\') |
|
| 272 | + { |
|
| 249 | 273 | return (\function_exists('sapi_windows_vt100_support') && @\sapi_windows_vt100_support($stream)) |
| 250 | 274 | || \getenv('ANSICON') !== false |
| 251 | 275 | || \getenv('ConEmuANSI') === 'ON' |
@@ -253,7 +277,9 @@ discard block |
||
| 253 | 277 | } |
| 254 | 278 | |
| 255 | 279 | return @\stream_isatty($stream); |
| 256 | - } catch (\Throwable) { |
|
| 280 | + } |
|
| 281 | + catch (\Throwable) |
|
| 282 | + { |
|
| 257 | 283 | return false; |
| 258 | 284 | } |
| 259 | 285 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | #[Proxy] private readonly ContainerInterface $container = new Container(), |
| 39 | 39 | private readonly ScopeInterface $scope = new Container(), |
| 40 | 40 | private readonly ?EventDispatcherInterface $dispatcher = null, |
| 41 | - ) {} |
|
| 41 | + ){} |
|
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * Run console application. |
@@ -62,14 +62,14 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | public function run( |
| 64 | 64 | ?string $command, |
| 65 | - array|InputInterface $input = [], |
|
| 65 | + array | InputInterface $input = [], |
|
| 66 | 66 | OutputInterface $output = new BufferedOutput(), |
| 67 | 67 | ): CommandOutput { |
| 68 | 68 | $input = \is_array($input) ? new ArrayInput($input) : $input; |
| 69 | 69 | |
| 70 | 70 | $this->configureIO($input, $output); |
| 71 | 71 | |
| 72 | - if ($command !== null) { |
|
| 72 | + if ($command !== null){ |
|
| 73 | 73 | $input = new InputProxy($input, ['firstArgument' => $command]); |
| 74 | 74 | } |
| 75 | 75 | |
@@ -96,18 +96,18 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | public function getApplication(): Application |
| 98 | 98 | { |
| 99 | - if ($this->application !== null) { |
|
| 99 | + if ($this->application !== null){ |
|
| 100 | 100 | return $this->application; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | $this->application = new Application($this->config->getName(), $this->config->getVersion()); |
| 104 | 104 | $this->application->setCatchExceptions(false); |
| 105 | 105 | $this->application->setAutoExit(false); |
| 106 | - if ($this->dispatcher instanceof SymfonyEventDispatcherInterface) { |
|
| 106 | + if ($this->dispatcher instanceof SymfonyEventDispatcherInterface){ |
|
| 107 | 107 | $this->application->setDispatcher($this->dispatcher); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if ($this->locator !== null) { |
|
| 110 | + if ($this->locator !== null){ |
|
| 111 | 111 | $this->addCommands($this->locator->locateCommands()); |
| 112 | 112 | } |
| 113 | 113 | |
@@ -130,13 +130,13 @@ discard block |
||
| 130 | 130 | ? $this->application->addCommand(...) |
| 131 | 131 | : $this->application->add(...); |
| 132 | 132 | |
| 133 | - foreach ($commands as $command) { |
|
| 134 | - if ($command instanceof Command) { |
|
| 133 | + foreach ($commands as $command){ |
|
| 134 | + if ($command instanceof Command){ |
|
| 135 | 135 | $command->setContainer($this->container); |
| 136 | 136 | $command->setInterceptors($interceptors); |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - if ($this->dispatcher !== null && $command instanceof EventDispatcherAwareInterface) { |
|
| 139 | + if ($this->dispatcher !== null && $command instanceof EventDispatcherAwareInterface){ |
|
| 140 | 140 | $command->setEventDispatcher($this->dispatcher); |
| 141 | 141 | } |
| 142 | 142 | |
@@ -151,27 +151,27 @@ discard block |
||
| 151 | 151 | */ |
| 152 | 152 | private function configureIO(InputInterface $input, OutputInterface $output): void |
| 153 | 153 | { |
| 154 | - if ($input->hasParameterOption(['--ansi'], true)) { |
|
| 154 | + if ($input->hasParameterOption(['--ansi'], true)){ |
|
| 155 | 155 | $output->setDecorated(true); |
| 156 | - } elseif ($input->hasParameterOption(['--no-ansi'], true)) { |
|
| 156 | + } elseif ($input->hasParameterOption(['--no-ansi'], true)){ |
|
| 157 | 157 | $output->setDecorated(false); |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - if ($input->hasParameterOption(['--no-interaction', '-n'], true)) { |
|
| 160 | + if ($input->hasParameterOption(['--no-interaction', '-n'], true)){ |
|
| 161 | 161 | $input->setInteractive(false); |
| 162 | - } elseif (\function_exists('posix_isatty')) { |
|
| 162 | + } elseif (\function_exists('posix_isatty')){ |
|
| 163 | 163 | $inputStream = null; |
| 164 | 164 | |
| 165 | - if ($input instanceof StreamableInputInterface) { |
|
| 165 | + if ($input instanceof StreamableInputInterface){ |
|
| 166 | 166 | $inputStream = $input->getStream(); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - if ($inputStream !== null && !@posix_isatty($inputStream) && \getenv('SHELL_INTERACTIVE') === false) { |
|
| 169 | + if ($inputStream !== null && !@posix_isatty($inputStream) && \getenv('SHELL_INTERACTIVE') === false){ |
|
| 170 | 170 | $input->setInteractive(false); |
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - match ($shellVerbosity = (int) \getenv('SHELL_VERBOSITY')) { |
|
| 174 | + match ($shellVerbosity = (int)\getenv('SHELL_VERBOSITY')) { |
|
| 175 | 175 | -1 => $output->setVerbosity(OutputInterface::VERBOSITY_QUIET), |
| 176 | 176 | 1 => $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE), |
| 177 | 177 | 2 => $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE), |
@@ -179,22 +179,22 @@ discard block |
||
| 179 | 179 | default => $shellVerbosity = 0, |
| 180 | 180 | }; |
| 181 | 181 | |
| 182 | - if ($input->hasParameterOption(['--quiet', '-q'], true)) { |
|
| 182 | + if ($input->hasParameterOption(['--quiet', '-q'], true)){ |
|
| 183 | 183 | $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); |
| 184 | 184 | $shellVerbosity = -1; |
| 185 | - } else { |
|
| 185 | + }else{ |
|
| 186 | 186 | if ( |
| 187 | 187 | $input->hasParameterOption('-vvv', true) |
| 188 | 188 | || $input->hasParameterOption('--verbose=3', true) |
| 189 | 189 | || $input->getParameterOption('--verbose', false, true) === 3 |
| 190 | - ) { |
|
| 190 | + ){ |
|
| 191 | 191 | $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG); |
| 192 | 192 | $shellVerbosity = 3; |
| 193 | 193 | } elseif ( |
| 194 | 194 | $input->hasParameterOption('-vv', true) |
| 195 | 195 | || $input->hasParameterOption('--verbose=2', true) |
| 196 | 196 | || $input->getParameterOption('--verbose', false, true) === 2 |
| 197 | - ) { |
|
| 197 | + ){ |
|
| 198 | 198 | $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); |
| 199 | 199 | $shellVerbosity = 2; |
| 200 | 200 | } elseif ( |
@@ -202,17 +202,17 @@ discard block |
||
| 202 | 202 | || $input->hasParameterOption('--verbose=1', true) |
| 203 | 203 | || $input->hasParameterOption('--verbose', true) |
| 204 | 204 | || $input->getParameterOption('--verbose', false, true) |
| 205 | - ) { |
|
| 205 | + ){ |
|
| 206 | 206 | $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); |
| 207 | 207 | $shellVerbosity = 1; |
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - if ($shellVerbosity === -1) { |
|
| 211 | + if ($shellVerbosity === -1){ |
|
| 212 | 212 | $input->setInteractive(false); |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - \putenv('SHELL_VERBOSITY=' . $shellVerbosity); |
|
| 215 | + \putenv('SHELL_VERBOSITY='.$shellVerbosity); |
|
| 216 | 216 | $_ENV['SHELL_VERBOSITY'] = $shellVerbosity; |
| 217 | 217 | $_SERVER['SHELL_VERBOSITY'] = $shellVerbosity; |
| 218 | 218 | } |
@@ -38,7 +38,8 @@ discard block |
||
| 38 | 38 | #[Proxy] private readonly ContainerInterface $container = new Container(), |
| 39 | 39 | private readonly ScopeInterface $scope = new Container(), |
| 40 | 40 | private readonly ?EventDispatcherInterface $dispatcher = null, |
| 41 | - ) {} |
|
| 41 | + ) { |
|
| 42 | +} |
|
| 42 | 43 | |
| 43 | 44 | /** |
| 44 | 45 | * Run console application. |
@@ -69,7 +70,8 @@ discard block |
||
| 69 | 70 | |
| 70 | 71 | $this->configureIO($input, $output); |
| 71 | 72 | |
| 72 | - if ($command !== null) { |
|
| 73 | + if ($command !== null) |
|
| 74 | + { |
|
| 73 | 75 | $input = new InputProxy($input, ['firstArgument' => $command]); |
| 74 | 76 | } |
| 75 | 77 | |
@@ -96,18 +98,21 @@ discard block |
||
| 96 | 98 | */ |
| 97 | 99 | public function getApplication(): Application |
| 98 | 100 | { |
| 99 | - if ($this->application !== null) { |
|
| 101 | + if ($this->application !== null) |
|
| 102 | + { |
|
| 100 | 103 | return $this->application; |
| 101 | 104 | } |
| 102 | 105 | |
| 103 | 106 | $this->application = new Application($this->config->getName(), $this->config->getVersion()); |
| 104 | 107 | $this->application->setCatchExceptions(false); |
| 105 | 108 | $this->application->setAutoExit(false); |
| 106 | - if ($this->dispatcher instanceof SymfonyEventDispatcherInterface) { |
|
| 109 | + if ($this->dispatcher instanceof SymfonyEventDispatcherInterface) |
|
| 110 | + { |
|
| 107 | 111 | $this->application->setDispatcher($this->dispatcher); |
| 108 | 112 | } |
| 109 | 113 | |
| 110 | - if ($this->locator !== null) { |
|
| 114 | + if ($this->locator !== null) |
|
| 115 | + { |
|
| 111 | 116 | $this->addCommands($this->locator->locateCommands()); |
| 112 | 117 | } |
| 113 | 118 | |
@@ -130,13 +135,16 @@ discard block |
||
| 130 | 135 | ? $this->application->addCommand(...) |
| 131 | 136 | : $this->application->add(...); |
| 132 | 137 | |
| 133 | - foreach ($commands as $command) { |
|
| 134 | - if ($command instanceof Command) { |
|
| 138 | + foreach ($commands as $command) |
|
| 139 | + { |
|
| 140 | + if ($command instanceof Command) |
|
| 141 | + { |
|
| 135 | 142 | $command->setContainer($this->container); |
| 136 | 143 | $command->setInterceptors($interceptors); |
| 137 | 144 | } |
| 138 | 145 | |
| 139 | - if ($this->dispatcher !== null && $command instanceof EventDispatcherAwareInterface) { |
|
| 146 | + if ($this->dispatcher !== null && $command instanceof EventDispatcherAwareInterface) |
|
| 147 | + { |
|
| 140 | 148 | $command->setEventDispatcher($this->dispatcher); |
| 141 | 149 | } |
| 142 | 150 | |
@@ -151,22 +159,30 @@ discard block |
||
| 151 | 159 | */ |
| 152 | 160 | private function configureIO(InputInterface $input, OutputInterface $output): void |
| 153 | 161 | { |
| 154 | - if ($input->hasParameterOption(['--ansi'], true)) { |
|
| 162 | + if ($input->hasParameterOption(['--ansi'], true)) |
|
| 163 | + { |
|
| 155 | 164 | $output->setDecorated(true); |
| 156 | - } elseif ($input->hasParameterOption(['--no-ansi'], true)) { |
|
| 165 | + } |
|
| 166 | + elseif ($input->hasParameterOption(['--no-ansi'], true)) |
|
| 167 | + { |
|
| 157 | 168 | $output->setDecorated(false); |
| 158 | 169 | } |
| 159 | 170 | |
| 160 | - if ($input->hasParameterOption(['--no-interaction', '-n'], true)) { |
|
| 171 | + if ($input->hasParameterOption(['--no-interaction', '-n'], true)) |
|
| 172 | + { |
|
| 161 | 173 | $input->setInteractive(false); |
| 162 | - } elseif (\function_exists('posix_isatty')) { |
|
| 174 | + } |
|
| 175 | + elseif (\function_exists('posix_isatty')) |
|
| 176 | + { |
|
| 163 | 177 | $inputStream = null; |
| 164 | 178 | |
| 165 | - if ($input instanceof StreamableInputInterface) { |
|
| 179 | + if ($input instanceof StreamableInputInterface) |
|
| 180 | + { |
|
| 166 | 181 | $inputStream = $input->getStream(); |
| 167 | 182 | } |
| 168 | 183 | |
| 169 | - if ($inputStream !== null && !@posix_isatty($inputStream) && \getenv('SHELL_INTERACTIVE') === false) { |
|
| 184 | + if ($inputStream !== null && !@posix_isatty($inputStream) && \getenv('SHELL_INTERACTIVE') === false) |
|
| 185 | + { |
|
| 170 | 186 | $input->setInteractive(false); |
| 171 | 187 | } |
| 172 | 188 | } |
@@ -179,10 +195,13 @@ discard block |
||
| 179 | 195 | default => $shellVerbosity = 0, |
| 180 | 196 | }; |
| 181 | 197 | |
| 182 | - if ($input->hasParameterOption(['--quiet', '-q'], true)) { |
|
| 198 | + if ($input->hasParameterOption(['--quiet', '-q'], true)) |
|
| 199 | + { |
|
| 183 | 200 | $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); |
| 184 | 201 | $shellVerbosity = -1; |
| 185 | - } else { |
|
| 202 | + } |
|
| 203 | + else |
|
| 204 | + { |
|
| 186 | 205 | if ( |
| 187 | 206 | $input->hasParameterOption('-vvv', true) |
| 188 | 207 | || $input->hasParameterOption('--verbose=3', true) |
@@ -190,14 +209,16 @@ discard block |
||
| 190 | 209 | ) { |
| 191 | 210 | $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG); |
| 192 | 211 | $shellVerbosity = 3; |
| 193 | - } elseif ( |
|
| 212 | + } |
|
| 213 | + elseif ( |
|
| 194 | 214 | $input->hasParameterOption('-vv', true) |
| 195 | 215 | || $input->hasParameterOption('--verbose=2', true) |
| 196 | 216 | || $input->getParameterOption('--verbose', false, true) === 2 |
| 197 | 217 | ) { |
| 198 | 218 | $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); |
| 199 | 219 | $shellVerbosity = 2; |
| 200 | - } elseif ( |
|
| 220 | + } |
|
| 221 | + elseif ( |
|
| 201 | 222 | $input->hasParameterOption('-v', true) |
| 202 | 223 | || $input->hasParameterOption('--verbose=1', true) |
| 203 | 224 | || $input->hasParameterOption('--verbose', true) |
@@ -208,7 +229,8 @@ discard block |
||
| 208 | 229 | } |
| 209 | 230 | } |
| 210 | 231 | |
| 211 | - if ($shellVerbosity === -1) { |
|
| 232 | + if ($shellVerbosity === -1) |
|
| 233 | + { |
|
| 212 | 234 | $input->setInteractive(false); |
| 213 | 235 | } |
| 214 | 236 | |
@@ -8,7 +8,7 @@ |
||
| 8 | 8 | { |
| 9 | 9 | public function getParameter(): string |
| 10 | 10 | { |
| 11 | - return '#' . $this->parameter; |
|
| 11 | + return '#'.$this->parameter; |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | protected function getValidationMessage( |
@@ -48,11 +48,11 @@ discard block |
||
| 48 | 48 | public const DEFAULT_ROOT_SCOPE_NAME = 'root'; |
| 49 | 49 | |
| 50 | 50 | private Internal\State $state; |
| 51 | - private ResolverInterface|Internal\Resolver $resolver; |
|
| 52 | - private FactoryInterface|Internal\Factory $factory; |
|
| 53 | - private ContainerInterface|Internal\Container $container; |
|
| 54 | - private BinderInterface|Internal\Binder $binder; |
|
| 55 | - private InvokerInterface|Internal\Invoker $invoker; |
|
| 51 | + private ResolverInterface | Internal\Resolver $resolver; |
|
| 52 | + private FactoryInterface | Internal\Factory $factory; |
|
| 53 | + private ContainerInterface | Internal\Container $container; |
|
| 54 | + private BinderInterface | Internal\Binder $binder; |
|
| 55 | + private InvokerInterface | Internal\Invoker $invoker; |
|
| 56 | 56 | private Internal\Scope $scope; |
| 57 | 57 | private Internal\Actor $actor; |
| 58 | 58 | |
@@ -61,11 +61,11 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | public function __construct( |
| 63 | 63 | private Config $config = new Config(), |
| 64 | - string|\BackedEnum|null $scopeName = self::DEFAULT_ROOT_SCOPE_NAME, |
|
| 64 | + string | \BackedEnum | null $scopeName = self::DEFAULT_ROOT_SCOPE_NAME, |
|
| 65 | 65 | private Options $options = new Options(), |
| 66 | - ) { |
|
| 67 | - if (\is_object($scopeName)) { |
|
| 68 | - $scopeName = (string) $scopeName->value; |
|
| 66 | + ){ |
|
| 67 | + if (\is_object($scopeName)){ |
|
| 68 | + $scopeName = (string)$scopeName->value; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | $this->initServices($this, $scopeName); |
@@ -106,11 +106,11 @@ discard block |
||
| 106 | 106 | * @throws \Throwable |
| 107 | 107 | * @psalm-suppress TooManyArguments |
| 108 | 108 | */ |
| 109 | - public function make(string $alias, array $parameters = [], \Stringable|string|null $context = null): mixed |
|
| 109 | + public function make(string $alias, array $parameters = [], \Stringable | string | null $context = null): mixed |
|
| 110 | 110 | { |
| 111 | 111 | return ContainerScope::getContainer() === $this |
| 112 | 112 | ? $this->factory->make($alias, $parameters, $context) |
| 113 | - : ContainerScope::runScope($this, fn(): mixed => $this->factory->make($alias, $parameters, $context)); |
|
| 113 | + : ContainerScope::runScope($this, fn() : mixed => $this->factory->make($alias, $parameters, $context)); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | * @throws \Throwable |
| 133 | 133 | * @psalm-suppress TooManyArguments |
| 134 | 134 | */ |
| 135 | - public function get(string|Autowire $id, \Stringable|string|null $context = null): mixed |
|
| 135 | + public function get(string | Autowire $id, \Stringable | string | null $context = null): mixed |
|
| 136 | 136 | { |
| 137 | 137 | return ContainerScope::getContainer() === $this |
| 138 | 138 | ? $this->container->get($id, $context) |
@@ -152,9 +152,9 @@ discard block |
||
| 152 | 152 | * If {@see string}, the default binder for the given scope will be returned. Default bindings won't affect |
| 153 | 153 | * already created Container instances except the case with the root one. |
| 154 | 154 | */ |
| 155 | - public function getBinder(string|\BackedEnum|null $scope = null): BinderInterface |
|
| 155 | + public function getBinder(string | \BackedEnum | null $scope = null): BinderInterface |
|
| 156 | 156 | { |
| 157 | - $scope = \is_object($scope) ? (string) $scope->value : $scope; |
|
| 157 | + $scope = \is_object($scope) ? (string)$scope->value : $scope; |
|
| 158 | 158 | |
| 159 | 159 | return $scope === null |
| 160 | 160 | ? $this->binder |
@@ -164,25 +164,25 @@ discard block |
||
| 164 | 164 | /** |
| 165 | 165 | * @throws \Throwable |
| 166 | 166 | */ |
| 167 | - public function runScope(Scope|array $bindings, callable $scope): mixed |
|
| 167 | + public function runScope(Scope | array $bindings, callable $scope): mixed |
|
| 168 | 168 | { |
| 169 | - if (!\is_array($bindings)) { |
|
| 169 | + if (!\is_array($bindings)){ |
|
| 170 | 170 | return $this->runIsolatedScope($bindings, $scope); |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | $binds = &$this->state->bindings; |
| 174 | 174 | $singletons = &$this->state->singletons; |
| 175 | 175 | $cleanup = $previous = $prevSin = []; |
| 176 | - foreach ($bindings as $alias => $resolver) { |
|
| 176 | + foreach ($bindings as $alias => $resolver){ |
|
| 177 | 177 | // Store previous bindings |
| 178 | - if (isset($binds[$alias])) { |
|
| 178 | + if (isset($binds[$alias])){ |
|
| 179 | 179 | $previous[$alias] = $binds[$alias]; |
| 180 | - } else { |
|
| 180 | + }else{ |
|
| 181 | 181 | // Store bindings to be removed |
| 182 | 182 | $cleanup[] = $alias; |
| 183 | 183 | } |
| 184 | 184 | // Store previous singletons |
| 185 | - if (isset($singletons[$alias])) { |
|
| 185 | + if (isset($singletons[$alias])){ |
|
| 186 | 186 | $prevSin[$alias] = $singletons[$alias]; |
| 187 | 187 | unset($singletons[$alias]); |
| 188 | 188 | } |
@@ -190,21 +190,21 @@ discard block |
||
| 190 | 190 | $this->binder->bind($alias, $resolver); |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - try { |
|
| 193 | + try{ |
|
| 194 | 194 | return ContainerScope::getContainer() !== $this |
| 195 | 195 | ? ContainerScope::runScope($this, $scope) |
| 196 | 196 | : $scope($this); |
| 197 | - } finally { |
|
| 197 | + }finally{ |
|
| 198 | 198 | // Remove new bindings |
| 199 | - foreach ($cleanup as $alias) { |
|
| 199 | + foreach ($cleanup as $alias){ |
|
| 200 | 200 | unset($binds[$alias], $singletons[$alias]); |
| 201 | 201 | } |
| 202 | 202 | // Restore previous bindings |
| 203 | - foreach ($previous as $alias => $resolver) { |
|
| 203 | + foreach ($previous as $alias => $resolver){ |
|
| 204 | 204 | $binds[$alias] = $resolver; |
| 205 | 205 | } |
| 206 | 206 | // Restore singletons |
| 207 | - foreach ($prevSin as $alias => $instance) { |
|
| 207 | + foreach ($prevSin as $alias => $instance){ |
|
| 208 | 208 | $singletons[$alias] = $instance; |
| 209 | 209 | } |
| 210 | 210 | } |
@@ -252,9 +252,9 @@ discard block |
||
| 252 | 252 | * @psalm-param TResolver $resolver |
| 253 | 253 | * @throws SingletonOverloadException |
| 254 | 254 | */ |
| 255 | - public function bindSingleton(string $alias, string|array|callable|object $resolver, ?bool $force = null): void |
|
| 255 | + public function bindSingleton(string $alias, string | array | callable | object $resolver, ?bool $force = null): void |
|
| 256 | 256 | { |
| 257 | - if ($force ?? $this->options->allowSingletonsRebinding) { |
|
| 257 | + if ($force ?? $this->options->allowSingletonsRebinding){ |
|
| 258 | 258 | $this->binder->removeBinding($alias); |
| 259 | 259 | } |
| 260 | 260 | |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | { |
| 290 | 290 | return ContainerScope::getContainer() === $this |
| 291 | 291 | ? $this->invoker->invoke($target, $parameters) |
| 292 | - : ContainerScope::runScope($this, fn(): mixed => $this->invoker->invoke($target, $parameters)); |
|
| 292 | + : ContainerScope::runScope($this, fn() : mixed => $this->invoker->invoke($target, $parameters)); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
@@ -346,8 +346,8 @@ discard block |
||
| 346 | 346 | ], $this->options); |
| 347 | 347 | |
| 348 | 348 | // Create container services |
| 349 | - foreach ($container->config as $property => $class) { |
|
| 350 | - if (\property_exists($container, $property)) { |
|
| 349 | + foreach ($container->config as $property => $class){ |
|
| 350 | + if (\property_exists($container, $property)){ |
|
| 351 | 351 | $container->$property = $constructor->get($property, $class); |
| 352 | 352 | } |
| 353 | 353 | } |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | private function closeScope(): void |
| 362 | 362 | { |
| 363 | 363 | /** @psalm-suppress RedundantPropertyInitializationCheck */ |
| 364 | - if (!isset($this->scope)) { |
|
| 364 | + if (!isset($this->scope)){ |
|
| 365 | 365 | $this->destruct(); |
| 366 | 366 | return; |
| 367 | 367 | } |
@@ -370,10 +370,10 @@ discard block |
||
| 370 | 370 | |
| 371 | 371 | // Run finalizers |
| 372 | 372 | $errors = []; |
| 373 | - foreach ($this->state->finalizers as $finalizer) { |
|
| 374 | - try { |
|
| 373 | + foreach ($this->state->finalizers as $finalizer){ |
|
| 374 | + try{ |
|
| 375 | 375 | $this->invoker->invoke($finalizer); |
| 376 | - } catch (\Throwable $e) { |
|
| 376 | + }catch (\Throwable $e){ |
|
| 377 | 377 | $errors[] = $e; |
| 378 | 378 | } |
| 379 | 379 | } |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | $this->destruct(); |
| 383 | 383 | |
| 384 | 384 | // Throw collected errors |
| 385 | - if ($errors !== []) { |
|
| 385 | + if ($errors !== []){ |
|
| 386 | 386 | throw new FinalizersException($scopeName, $errors); |
| 387 | 387 | } |
| 388 | 388 | } |
@@ -404,18 +404,18 @@ discard block |
||
| 404 | 404 | $container->scope->setParent($this, $this->scope, $this->actor); |
| 405 | 405 | |
| 406 | 406 | // Add specific bindings |
| 407 | - foreach ($config->bindings as $alias => $resolver) { |
|
| 407 | + foreach ($config->bindings as $alias => $resolver){ |
|
| 408 | 408 | $container->binder->bind($alias, $resolver); |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | return ContainerScope::runScope( |
| 412 | 412 | $container, |
| 413 | 413 | static function (self $container) use ($config, $closure): mixed { |
| 414 | - try { |
|
| 414 | + try{ |
|
| 415 | 415 | return $config->autowire |
| 416 | 416 | ? $container->invoke($closure) |
| 417 | 417 | : $closure($container); |
| 418 | - } finally { |
|
| 418 | + }finally{ |
|
| 419 | 419 | $container->closeScope(); |
| 420 | 420 | } |
| 421 | 421 | }, |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | public function __construct( |
| 13 | 13 | public readonly object $value, |
| 14 | 14 | public readonly bool $singleton = false, |
| 15 | - ) {} |
|
| 15 | + ){} |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * @return class-string |
@@ -25,6 +25,6 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | public function __toString(): string |
| 27 | 27 | { |
| 28 | - return 'Shared object of class ' . $this->value::class; |
|
| 28 | + return 'Shared object of class '.$this->value::class; |
|
| 29 | 29 | } |
| 30 | 30 | } |
@@ -12,7 +12,8 @@ |
||
| 12 | 12 | public function __construct( |
| 13 | 13 | public readonly object $value, |
| 14 | 14 | public readonly bool $singleton = false, |
| 15 | - ) {} |
|
| 15 | + ) { |
|
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * @return class-string |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | public function resolveType( |
| 88 | 88 | string $alias, |
| 89 | - ?Binding &$binding = null, |
|
| 89 | + ?Binding & $binding = null, |
|
| 90 | 90 | ?object &$singleton = null, |
| 91 | 91 | ?object &$injector = null, |
| 92 | 92 | ?self &$actor = null, |
@@ -95,20 +95,20 @@ discard block |
||
| 95 | 95 | // Aliases to prevent circular dependencies |
| 96 | 96 | $as = []; |
| 97 | 97 | $actor = $this; |
| 98 | - do { |
|
| 98 | + do{ |
|
| 99 | 99 | $bindings = &$actor->state->bindings; |
| 100 | 100 | $singletons = &$actor->state->singletons; |
| 101 | 101 | $injectors = &$actor->state->injectors; |
| 102 | 102 | $binding = $bindings[$alias] ?? null; |
| 103 | - if (\array_key_exists($alias, $singletons)) { |
|
| 103 | + if (\array_key_exists($alias, $singletons)){ |
|
| 104 | 104 | $singleton = $singletons[$alias]; |
| 105 | 105 | $injector = $injectors[$alias] ?? null; |
| 106 | 106 | return \is_object($singleton::class) ? $singleton::class : null; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - if ($binding !== null) { |
|
| 110 | - if ($followAlias && $binding::class === Alias::class) { |
|
| 111 | - if ($binding->alias === $alias) { |
|
| 109 | + if ($binding !== null){ |
|
| 110 | + if ($followAlias && $binding::class === Alias::class){ |
|
| 111 | + if ($binding->alias === $alias){ |
|
| 112 | 112 | break; |
| 113 | 113 | } |
| 114 | 114 | |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | return $binding->getReturnClass(); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - if (\array_key_exists($alias, $injectors)) { |
|
| 126 | + if (\array_key_exists($alias, $injectors)){ |
|
| 127 | 127 | $injector = $injectors[$alias]; |
| 128 | 128 | $binding = $bindings[$alias] ?? null; |
| 129 | 129 | return $alias; |
@@ -131,12 +131,12 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | // Go to parent scope |
| 133 | 133 | $parent = $actor->scope->getParentActor(); |
| 134 | - if ($parent === null) { |
|
| 134 | + if ($parent === null){ |
|
| 135 | 135 | break; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | $actor = $parent; |
| 139 | - } while (true); |
|
| 139 | + }while (true); |
|
| 140 | 140 | |
| 141 | 141 | return \class_exists($alias) ? $alias : null; |
| 142 | 142 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | public function resolveBinding( |
| 145 | 145 | object $binding, |
| 146 | 146 | string $alias, |
| 147 | - \Stringable|string|null $context, |
|
| 147 | + \Stringable | string | null $context, |
|
| 148 | 148 | array $arguments, |
| 149 | 149 | Tracer $tracer, |
| 150 | 150 | ): mixed { |
@@ -201,18 +201,18 @@ discard block |
||
| 201 | 201 | private function resolveInjector(Config\Injectable $binding, Ctx $ctx, array $arguments, Tracer $tracer) |
| 202 | 202 | { |
| 203 | 203 | $context = $ctx->context; |
| 204 | - try { |
|
| 204 | + try{ |
|
| 205 | 205 | $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class); |
| 206 | - } catch (\ReflectionException $e) { |
|
| 206 | + }catch (\ReflectionException $e){ |
|
| 207 | 207 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | $injector = $binding->injector; |
| 211 | 211 | |
| 212 | - try { |
|
| 212 | + try{ |
|
| 213 | 213 | $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector); |
| 214 | 214 | |
| 215 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
| 215 | + if (!$injectorInstance instanceof InjectorInterface){ |
|
| 216 | 216 | throw new InjectionException( |
| 217 | 217 | \sprintf( |
| 218 | 218 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | static $cache = []; |
| 227 | 227 | $extended = $cache[$injectorInstance::class] ??= ( |
| 228 | 228 | static fn(\ReflectionType $type): bool => |
| 229 | - $type::class === \ReflectionUnionType::class || (string) $type === 'mixed' |
|
| 229 | + $type::class === \ReflectionUnionType::class || (string)$type === 'mixed' |
|
| 230 | 230 | )( |
| 231 | 231 | ($refMethod = new \ReflectionMethod($injectorInstance, 'createInjection')) |
| 232 | 232 | ->getParameters()[1]->getType() |
@@ -236,10 +236,10 @@ discard block |
||
| 236 | 236 | $instance = $injectorInstance->createInjection($reflection, match (true) { |
| 237 | 237 | $asIs => $context, |
| 238 | 238 | $context instanceof \ReflectionParameter => $context->getName(), |
| 239 | - default => (string) $context, |
|
| 239 | + default => (string)$context, |
|
| 240 | 240 | }); |
| 241 | 241 | |
| 242 | - if (!$reflection->isInstance($instance)) { |
|
| 242 | + if (!$reflection->isInstance($instance)){ |
|
| 243 | 243 | throw new InjectionException( |
| 244 | 244 | \sprintf( |
| 245 | 245 | "Invalid injection response for '%s'.", |
@@ -249,12 +249,12 @@ discard block |
||
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | return $instance; |
| 252 | - } catch (TracedContainerException $e) { |
|
| 252 | + }catch (TracedContainerException $e){ |
|
| 253 | 253 | throw isset($injectorInstance) ? $e : $e::createWithTrace(\sprintf( |
| 254 | 254 | 'Can\'t resolve `%s`.', |
| 255 | 255 | $tracer->getRootAlias(), |
| 256 | 256 | ), $tracer->getTraces(), $e); |
| 257 | - } finally { |
|
| 257 | + }finally{ |
|
| 258 | 258 | $this->state->bindings[$ctx->class] ??= $binding; |
| 259 | 259 | } |
| 260 | 260 | } |
@@ -262,22 +262,22 @@ discard block |
||
| 262 | 262 | private function resolveAlias( |
| 263 | 263 | Config\Alias $binding, |
| 264 | 264 | string $alias, |
| 265 | - \Stringable|string|null $context, |
|
| 265 | + \Stringable | string | null $context, |
|
| 266 | 266 | array $arguments, |
| 267 | 267 | Tracer $tracer, |
| 268 | 268 | ): mixed { |
| 269 | - if ($binding->alias === $alias) { |
|
| 269 | + if ($binding->alias === $alias){ |
|
| 270 | 270 | $instance = $this->autowire( |
| 271 | 271 | new Ctx(alias: $alias, class: $binding->alias, context: $context, singleton: $binding->singleton && $arguments === []), |
| 272 | 272 | $arguments, |
| 273 | 273 | $this, |
| 274 | 274 | $tracer, |
| 275 | 275 | ); |
| 276 | - } else { |
|
| 277 | - try { |
|
| 276 | + }else{ |
|
| 277 | + try{ |
|
| 278 | 278 | //Binding is pointing to something else |
| 279 | 279 | $instance = $this->factory->make($binding->alias, $arguments, $context); |
| 280 | - } catch (TracedContainerException $e) { |
|
| 280 | + }catch (TracedContainerException $e){ |
|
| 281 | 281 | throw $e::createWithTrace( |
| 282 | 282 | $alias === $tracer->getRootAlias() |
| 283 | 283 | ? "Can't resolve `{$alias}`." |
@@ -294,9 +294,9 @@ discard block |
||
| 294 | 294 | return $instance; |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | - private function resolveProxy(Config\Proxy $binding, string $alias, \Stringable|string|null $context): mixed |
|
| 297 | + private function resolveProxy(Config\Proxy $binding, string $alias, \Stringable | string | null $context): mixed |
|
| 298 | 298 | { |
| 299 | - if ($context instanceof RetryContext) { |
|
| 299 | + if ($context instanceof RetryContext){ |
|
| 300 | 300 | return $binding->fallbackFactory === null |
| 301 | 301 | ? throw new RecursiveProxyException( |
| 302 | 302 | $alias, |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | |
| 308 | 308 | $result = Proxy::create(new \ReflectionClass($binding->getReturnClass()), $context, new Attribute\Proxy()); |
| 309 | 309 | |
| 310 | - if ($binding->singleton) { |
|
| 310 | + if ($binding->singleton){ |
|
| 311 | 311 | $this->state->singletons[$alias] = $result; |
| 312 | 312 | } |
| 313 | 313 | |
@@ -317,11 +317,11 @@ discard block |
||
| 317 | 317 | private function resolveShared( |
| 318 | 318 | Config\Shared $binding, |
| 319 | 319 | string $alias, |
| 320 | - \Stringable|string|null $context, |
|
| 320 | + \Stringable | string | null $context, |
|
| 321 | 321 | array $arguments, |
| 322 | 322 | Tracer $tracer, |
| 323 | 323 | ): object { |
| 324 | - if ($arguments !== []) { |
|
| 324 | + if ($arguments !== []){ |
|
| 325 | 325 | // Avoid singleton cache |
| 326 | 326 | return $this->createInstance( |
| 327 | 327 | new Ctx(alias: $alias, class: $binding->value::class, context: $context, singleton: false), |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | ); |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - if ($binding->singleton) { |
|
| 334 | + if ($binding->singleton){ |
|
| 335 | 335 | $this->state->singletons[$alias] = $binding->value; |
| 336 | 336 | } |
| 337 | 337 | |
@@ -341,16 +341,16 @@ discard block |
||
| 341 | 341 | private function resolveAutowire( |
| 342 | 342 | Config\Autowire $binding, |
| 343 | 343 | string $alias, |
| 344 | - \Stringable|string|null $context, |
|
| 344 | + \Stringable | string | null $context, |
|
| 345 | 345 | array $arguments, |
| 346 | 346 | Tracer $tracer, |
| 347 | 347 | ): mixed { |
| 348 | 348 | $target = $binding->autowire->alias; |
| 349 | 349 | $ctx = new Ctx(alias: $alias, class: $target, context: $context, singleton: $binding->singleton && $arguments === [] ?: null); |
| 350 | 350 | |
| 351 | - if ($alias === $target) { |
|
| 351 | + if ($alias === $target){ |
|
| 352 | 352 | $instance = $this->autowire($ctx, \array_merge($binding->autowire->parameters, $arguments), $this, $tracer); |
| 353 | - } else { |
|
| 353 | + }else{ |
|
| 354 | 354 | $instance = $binding->autowire->resolve($this->factory, $arguments); |
| 355 | 355 | $this->validateConstraint($instance, $ctx); |
| 356 | 356 | } |
@@ -359,32 +359,32 @@ discard block |
||
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | private function resolveFactory( |
| 362 | - Config\Factory|Config\DeferredFactory $binding, |
|
| 362 | + Config\Factory | Config\DeferredFactory $binding, |
|
| 363 | 363 | string $alias, |
| 364 | - \Stringable|string|null $context, |
|
| 364 | + \Stringable | string | null $context, |
|
| 365 | 365 | array $arguments, |
| 366 | 366 | Tracer $tracer, |
| 367 | 367 | ): mixed { |
| 368 | 368 | $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton && $arguments === [] ?: null); |
| 369 | - try { |
|
| 369 | + try{ |
|
| 370 | 370 | $instance = $binding::class === Config\Factory::class && $binding->getParametersCount() === 0 |
| 371 | 371 | ? ($binding->factory)() |
| 372 | 372 | : $this->invoker->invoke($binding->factory, $arguments); |
| 373 | - } catch (NotCallableException $e) { |
|
| 373 | + }catch (NotCallableException $e){ |
|
| 374 | 374 | throw TracedContainerException::createWithTrace( |
| 375 | 375 | \sprintf('Invalid callable binding for `%s`.', $ctx->alias), |
| 376 | 376 | $tracer->getTraces(), |
| 377 | 377 | $e, |
| 378 | 378 | ); |
| 379 | - } catch (TracedContainerException $e) { |
|
| 379 | + }catch (TracedContainerException $e){ |
|
| 380 | 380 | throw $e::createWithTrace( |
| 381 | 381 | \sprintf("Can't resolve `%s`: factory invocation failed.", $tracer->getRootAlias()), |
| 382 | 382 | $tracer->getTraces(), |
| 383 | 383 | $e, |
| 384 | 384 | ); |
| 385 | - } catch (ContainerExceptionInterface $e) { |
|
| 385 | + }catch (ContainerExceptionInterface $e){ |
|
| 386 | 386 | throw $e; |
| 387 | - } catch (\Throwable $e) { |
|
| 387 | + }catch (\Throwable $e){ |
|
| 388 | 388 | throw NotFoundException::createWithTrace( |
| 389 | 389 | \sprintf("Can't resolve `%s` due to factory invocation error: %s", $tracer->getRootAlias(), $e->getMessage()), |
| 390 | 390 | $tracer->getTraces(), |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | ); |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - if (\is_object($instance)) { |
|
| 395 | + if (\is_object($instance)){ |
|
| 396 | 396 | $this->validateConstraint($instance, $ctx); |
| 397 | 397 | return $this->registerInstance($ctx, $instance); |
| 398 | 398 | } |
@@ -403,14 +403,14 @@ discard block |
||
| 403 | 403 | private function resolveWeakReference( |
| 404 | 404 | Config\WeakReference $binding, |
| 405 | 405 | string $alias, |
| 406 | - \Stringable|string|null $context, |
|
| 406 | + \Stringable | string | null $context, |
|
| 407 | 407 | array $arguments, |
| 408 | 408 | Tracer $tracer, |
| 409 | 409 | ): ?object { |
| 410 | 410 | $avoidCache = $arguments !== []; |
| 411 | 411 | |
| 412 | - if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) { |
|
| 413 | - try { |
|
| 412 | + if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)){ |
|
| 413 | + try{ |
|
| 414 | 414 | $tracer->push(false, alias: $alias, source: \WeakReference::class, context: $context); |
| 415 | 415 | |
| 416 | 416 | $object = $this->createInstance( |
@@ -419,17 +419,17 @@ discard block |
||
| 419 | 419 | $this, |
| 420 | 420 | $tracer, |
| 421 | 421 | ); |
| 422 | - if ($avoidCache) { |
|
| 422 | + if ($avoidCache){ |
|
| 423 | 423 | return $object; |
| 424 | 424 | } |
| 425 | 425 | $binding->reference = \WeakReference::create($object); |
| 426 | - } catch (\Throwable) { |
|
| 426 | + }catch (\Throwable){ |
|
| 427 | 427 | throw TracedContainerException::createWithTrace(\sprintf( |
| 428 | 428 | 'Can\'t resolve `%s`: can\'t instantiate `%s` from WeakReference binding.', |
| 429 | 429 | $tracer->getRootAlias(), |
| 430 | 430 | $alias, |
| 431 | 431 | ), $tracer->getTraces()); |
| 432 | - } finally { |
|
| 432 | + }finally{ |
|
| 433 | 433 | $tracer->pop(); |
| 434 | 434 | } |
| 435 | 435 | } |
@@ -445,13 +445,13 @@ discard block |
||
| 445 | 445 | object $instance, |
| 446 | 446 | Ctx $ctx, |
| 447 | 447 | ): void { |
| 448 | - if ($this->options->checkScope) { |
|
| 448 | + if ($this->options->checkScope){ |
|
| 449 | 449 | // Check scope name |
| 450 | 450 | $ctx->reflection ??= new \ReflectionClass($instance); |
| 451 | 451 | $scopeName = ($ctx->reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
| 452 | - if ($scopeName !== null) { |
|
| 452 | + if ($scopeName !== null){ |
|
| 453 | 453 | $scope = $this->scope; |
| 454 | - while ($scope->getScopeName() !== $scopeName) { |
|
| 454 | + while ($scope->getScopeName() !== $scopeName){ |
|
| 455 | 455 | $scope = $scope->getParentScope() ?? throw new BadScopeException($scopeName, $instance::class); |
| 456 | 456 | } |
| 457 | 457 | } |
@@ -478,26 +478,26 @@ discard block |
||
| 478 | 478 | Tracer $tracer, |
| 479 | 479 | ): object { |
| 480 | 480 | $class = $ctx->class; |
| 481 | - try { |
|
| 481 | + try{ |
|
| 482 | 482 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
| 483 | - } catch (\ReflectionException $e) { |
|
| 483 | + }catch (\ReflectionException $e){ |
|
| 484 | 484 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | // Check Scope attribute |
| 488 | 488 | $actor = $fallbackActor ?? $this; |
| 489 | - if ($this->options->checkScope) { # todo |
|
| 489 | + if ($this->options->checkScope){ # todo |
|
| 490 | 490 | $ar = ($reflection->getAttributes(Attribute\Scope::class)[0] ?? null); |
| 491 | - if ($ar !== null) { |
|
| 491 | + if ($ar !== null){ |
|
| 492 | 492 | /** @var Attribute\Scope $attr */ |
| 493 | 493 | $attr = $ar->newInstance(); |
| 494 | 494 | $scope = $this->scope; |
| 495 | 495 | $actor = $this; |
| 496 | 496 | // Go through all parent scopes |
| 497 | 497 | $needed = $actor; |
| 498 | - while ($attr->name !== $scope->getScopeName()) { |
|
| 498 | + while ($attr->name !== $scope->getScopeName()){ |
|
| 499 | 499 | $needed = $scope->getParentActor(); |
| 500 | - if ($needed === null) { |
|
| 500 | + if ($needed === null){ |
|
| 501 | 501 | throw new BadScopeException($attr->name, $class); |
| 502 | 502 | } |
| 503 | 503 | |
@@ -510,11 +510,11 @@ discard block |
||
| 510 | 510 | } # todo |
| 511 | 511 | |
| 512 | 512 | // We have to construct class using external injector when we know the exact context |
| 513 | - if ($arguments === [] && $actor->binder->hasInjector($class)) { |
|
| 513 | + if ($arguments === [] && $actor->binder->hasInjector($class)){ |
|
| 514 | 514 | return $actor->resolveInjector($actor->state->bindings[$ctx->class], $ctx, $arguments, $tracer); |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | - if (!$reflection->isInstantiable()) { |
|
| 517 | + if (!$reflection->isInstantiable()){ |
|
| 518 | 518 | $itIs = match (true) { |
| 519 | 519 | $reflection->isEnum() => 'Enum', |
| 520 | 520 | $reflection->isAbstract() => 'Abstract class', |
@@ -528,8 +528,8 @@ discard block |
||
| 528 | 528 | |
| 529 | 529 | $constructor = $reflection->getConstructor(); |
| 530 | 530 | |
| 531 | - if ($constructor !== null) { |
|
| 532 | - try { |
|
| 531 | + if ($constructor !== null){ |
|
| 532 | + try{ |
|
| 533 | 533 | $newScope = $this !== $actor; |
| 534 | 534 | $debug = [ |
| 535 | 535 | 'action' => 'resolve arguments', |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | $tracer->push($newScope, ...$debug); |
| 544 | 544 | $tracer->push(true); |
| 545 | 545 | $args = $actor->resolver->resolveArguments($constructor, $arguments, $actor->options->validateArguments); |
| 546 | - } catch (\Throwable $e) { |
|
| 546 | + }catch (\Throwable $e){ |
|
| 547 | 547 | throw TracedContainerException::createWithTrace( |
| 548 | 548 | \sprintf( |
| 549 | 549 | "Can't resolve `%s`.", |
@@ -552,28 +552,28 @@ discard block |
||
| 552 | 552 | $tracer->getTraces(), |
| 553 | 553 | $e, |
| 554 | 554 | ); |
| 555 | - } finally { |
|
| 555 | + }finally{ |
|
| 556 | 556 | $tracer->pop($newScope); |
| 557 | 557 | $tracer->pop(false); |
| 558 | 558 | } |
| 559 | - try { |
|
| 559 | + try{ |
|
| 560 | 560 | // Using constructor with resolved arguments |
| 561 | 561 | $tracer->push(false, call: "$class::__construct", arguments: $args); |
| 562 | 562 | $tracer->push(true); |
| 563 | 563 | $instance = new $class(...$args); |
| 564 | - } catch (\TypeError $e) { |
|
| 564 | + }catch (\TypeError $e){ |
|
| 565 | 565 | throw new WrongTypeException($constructor, $e); |
| 566 | - } catch (TracedContainerException $e) { |
|
| 566 | + }catch (TracedContainerException $e){ |
|
| 567 | 567 | throw $e::createWithTrace(\sprintf( |
| 568 | 568 | 'Can\'t resolve `%s`: failed constructing `%s`.', |
| 569 | 569 | $tracer->getRootAlias(), |
| 570 | 570 | $class, |
| 571 | 571 | ), $tracer->getTraces(), $e); |
| 572 | - } finally { |
|
| 572 | + }finally{ |
|
| 573 | 573 | $tracer->pop(true); |
| 574 | 574 | $tracer->pop(false); |
| 575 | 575 | } |
| 576 | - } else { |
|
| 576 | + }else{ |
|
| 577 | 577 | // No constructor specified |
| 578 | 578 | $instance = $reflection->newInstance(); |
| 579 | 579 | } |
@@ -605,12 +605,12 @@ discard block |
||
| 605 | 605 | */ |
| 606 | 606 | private function isSingleton(Ctx $ctx): bool |
| 607 | 607 | { |
| 608 | - if (\is_bool($ctx->singleton)) { |
|
| 608 | + if (\is_bool($ctx->singleton)){ |
|
| 609 | 609 | return $ctx->singleton; |
| 610 | 610 | } |
| 611 | 611 | |
| 612 | 612 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
| 613 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
| 613 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)){ |
|
| 614 | 614 | return true; |
| 615 | 615 | } |
| 616 | 616 | |
@@ -624,7 +624,7 @@ discard block |
||
| 624 | 624 | * @var Attribute\Finalize|null $attribute |
| 625 | 625 | */ |
| 626 | 626 | $attribute = ($ctx->reflection->getAttributes(Attribute\Finalize::class)[0] ?? null)?->newInstance(); |
| 627 | - if ($attribute === null) { |
|
| 627 | + if ($attribute === null){ |
|
| 628 | 628 | return null; |
| 629 | 629 | } |
| 630 | 630 | |
@@ -638,10 +638,10 @@ discard block |
||
| 638 | 638 | { |
| 639 | 639 | $scope = $this->scope; |
| 640 | 640 | |
| 641 | - while ($scope !== null) { |
|
| 642 | - foreach ($this->state->inflectors as $class => $inflectors) { |
|
| 643 | - if ($instance instanceof $class) { |
|
| 644 | - foreach ($inflectors as $inflector) { |
|
| 641 | + while ($scope !== null){ |
|
| 642 | + foreach ($this->state->inflectors as $class => $inflectors){ |
|
| 643 | + if ($instance instanceof $class){ |
|
| 644 | + foreach ($inflectors as $inflector){ |
|
| 645 | 645 | $instance = $inflector->getParametersCount() > 1 |
| 646 | 646 | ? $this->invoker->invoke($inflector->inflector, [$instance]) |
| 647 | 647 | : ($inflector->inflector)($instance); |
@@ -657,9 +657,9 @@ discard block |
||
| 657 | 657 | |
| 658 | 658 | private function validateArguments(ContextFunction $reflection, array $arguments = []): bool |
| 659 | 659 | { |
| 660 | - try { |
|
| 660 | + try{ |
|
| 661 | 661 | $this->resolver->validateArguments($reflection, $arguments); |
| 662 | - } catch (\Throwable) { |
|
| 662 | + }catch (\Throwable){ |
|
| 663 | 663 | return false; |
| 664 | 664 | } |
| 665 | 665 | |
@@ -95,20 +95,25 @@ discard block |
||
| 95 | 95 | // Aliases to prevent circular dependencies |
| 96 | 96 | $as = []; |
| 97 | 97 | $actor = $this; |
| 98 | - do { |
|
| 98 | + do |
|
| 99 | + { |
|
| 99 | 100 | $bindings = &$actor->state->bindings; |
| 100 | 101 | $singletons = &$actor->state->singletons; |
| 101 | 102 | $injectors = &$actor->state->injectors; |
| 102 | 103 | $binding = $bindings[$alias] ?? null; |
| 103 | - if (\array_key_exists($alias, $singletons)) { |
|
| 104 | + if (\array_key_exists($alias, $singletons)) |
|
| 105 | + { |
|
| 104 | 106 | $singleton = $singletons[$alias]; |
| 105 | 107 | $injector = $injectors[$alias] ?? null; |
| 106 | 108 | return \is_object($singleton::class) ? $singleton::class : null; |
| 107 | 109 | } |
| 108 | 110 | |
| 109 | - if ($binding !== null) { |
|
| 110 | - if ($followAlias && $binding::class === Alias::class) { |
|
| 111 | - if ($binding->alias === $alias) { |
|
| 111 | + if ($binding !== null) |
|
| 112 | + { |
|
| 113 | + if ($followAlias && $binding::class === Alias::class) |
|
| 114 | + { |
|
| 115 | + if ($binding->alias === $alias) |
|
| 116 | + { |
|
| 112 | 117 | break; |
| 113 | 118 | } |
| 114 | 119 | |
@@ -123,7 +128,8 @@ discard block |
||
| 123 | 128 | return $binding->getReturnClass(); |
| 124 | 129 | } |
| 125 | 130 | |
| 126 | - if (\array_key_exists($alias, $injectors)) { |
|
| 131 | + if (\array_key_exists($alias, $injectors)) |
|
| 132 | + { |
|
| 127 | 133 | $injector = $injectors[$alias]; |
| 128 | 134 | $binding = $bindings[$alias] ?? null; |
| 129 | 135 | return $alias; |
@@ -131,7 +137,8 @@ discard block |
||
| 131 | 137 | |
| 132 | 138 | // Go to parent scope |
| 133 | 139 | $parent = $actor->scope->getParentActor(); |
| 134 | - if ($parent === null) { |
|
| 140 | + if ($parent === null) |
|
| 141 | + { |
|
| 135 | 142 | break; |
| 136 | 143 | } |
| 137 | 144 | |
@@ -201,18 +208,23 @@ discard block |
||
| 201 | 208 | private function resolveInjector(Config\Injectable $binding, Ctx $ctx, array $arguments, Tracer $tracer) |
| 202 | 209 | { |
| 203 | 210 | $context = $ctx->context; |
| 204 | - try { |
|
| 211 | + try |
|
| 212 | + { |
|
| 205 | 213 | $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class); |
| 206 | - } catch (\ReflectionException $e) { |
|
| 214 | + } |
|
| 215 | + catch (\ReflectionException $e) |
|
| 216 | + { |
|
| 207 | 217 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 208 | 218 | } |
| 209 | 219 | |
| 210 | 220 | $injector = $binding->injector; |
| 211 | 221 | |
| 212 | - try { |
|
| 222 | + try |
|
| 223 | + { |
|
| 213 | 224 | $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector); |
| 214 | 225 | |
| 215 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
| 226 | + if (!$injectorInstance instanceof InjectorInterface) |
|
| 227 | + { |
|
| 216 | 228 | throw new InjectionException( |
| 217 | 229 | \sprintf( |
| 218 | 230 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -239,7 +251,8 @@ discard block |
||
| 239 | 251 | default => (string) $context, |
| 240 | 252 | }); |
| 241 | 253 | |
| 242 | - if (!$reflection->isInstance($instance)) { |
|
| 254 | + if (!$reflection->isInstance($instance)) |
|
| 255 | + { |
|
| 243 | 256 | throw new InjectionException( |
| 244 | 257 | \sprintf( |
| 245 | 258 | "Invalid injection response for '%s'.", |
@@ -249,12 +262,16 @@ discard block |
||
| 249 | 262 | } |
| 250 | 263 | |
| 251 | 264 | return $instance; |
| 252 | - } catch (TracedContainerException $e) { |
|
| 265 | + } |
|
| 266 | + catch (TracedContainerException $e) |
|
| 267 | + { |
|
| 253 | 268 | throw isset($injectorInstance) ? $e : $e::createWithTrace(\sprintf( |
| 254 | 269 | 'Can\'t resolve `%s`.', |
| 255 | 270 | $tracer->getRootAlias(), |
| 256 | 271 | ), $tracer->getTraces(), $e); |
| 257 | - } finally { |
|
| 272 | + } |
|
| 273 | + finally |
|
| 274 | + { |
|
| 258 | 275 | $this->state->bindings[$ctx->class] ??= $binding; |
| 259 | 276 | } |
| 260 | 277 | } |
@@ -266,18 +283,24 @@ discard block |
||
| 266 | 283 | array $arguments, |
| 267 | 284 | Tracer $tracer, |
| 268 | 285 | ): mixed { |
| 269 | - if ($binding->alias === $alias) { |
|
| 286 | + if ($binding->alias === $alias) |
|
| 287 | + { |
|
| 270 | 288 | $instance = $this->autowire( |
| 271 | 289 | new Ctx(alias: $alias, class: $binding->alias, context: $context, singleton: $binding->singleton && $arguments === []), |
| 272 | 290 | $arguments, |
| 273 | 291 | $this, |
| 274 | 292 | $tracer, |
| 275 | 293 | ); |
| 276 | - } else { |
|
| 277 | - try { |
|
| 294 | + } |
|
| 295 | + else |
|
| 296 | + { |
|
| 297 | + try |
|
| 298 | + { |
|
| 278 | 299 | //Binding is pointing to something else |
| 279 | 300 | $instance = $this->factory->make($binding->alias, $arguments, $context); |
| 280 | - } catch (TracedContainerException $e) { |
|
| 301 | + } |
|
| 302 | + catch (TracedContainerException $e) |
|
| 303 | + { |
|
| 281 | 304 | throw $e::createWithTrace( |
| 282 | 305 | $alias === $tracer->getRootAlias() |
| 283 | 306 | ? "Can't resolve `{$alias}`." |
@@ -296,7 +319,8 @@ discard block |
||
| 296 | 319 | |
| 297 | 320 | private function resolveProxy(Config\Proxy $binding, string $alias, \Stringable|string|null $context): mixed |
| 298 | 321 | { |
| 299 | - if ($context instanceof RetryContext) { |
|
| 322 | + if ($context instanceof RetryContext) |
|
| 323 | + { |
|
| 300 | 324 | return $binding->fallbackFactory === null |
| 301 | 325 | ? throw new RecursiveProxyException( |
| 302 | 326 | $alias, |
@@ -307,7 +331,8 @@ discard block |
||
| 307 | 331 | |
| 308 | 332 | $result = Proxy::create(new \ReflectionClass($binding->getReturnClass()), $context, new Attribute\Proxy()); |
| 309 | 333 | |
| 310 | - if ($binding->singleton) { |
|
| 334 | + if ($binding->singleton) |
|
| 335 | + { |
|
| 311 | 336 | $this->state->singletons[$alias] = $result; |
| 312 | 337 | } |
| 313 | 338 | |
@@ -321,7 +346,8 @@ discard block |
||
| 321 | 346 | array $arguments, |
| 322 | 347 | Tracer $tracer, |
| 323 | 348 | ): object { |
| 324 | - if ($arguments !== []) { |
|
| 349 | + if ($arguments !== []) |
|
| 350 | + { |
|
| 325 | 351 | // Avoid singleton cache |
| 326 | 352 | return $this->createInstance( |
| 327 | 353 | new Ctx(alias: $alias, class: $binding->value::class, context: $context, singleton: false), |
@@ -331,7 +357,8 @@ discard block |
||
| 331 | 357 | ); |
| 332 | 358 | } |
| 333 | 359 | |
| 334 | - if ($binding->singleton) { |
|
| 360 | + if ($binding->singleton) |
|
| 361 | + { |
|
| 335 | 362 | $this->state->singletons[$alias] = $binding->value; |
| 336 | 363 | } |
| 337 | 364 | |
@@ -348,9 +375,12 @@ discard block |
||
| 348 | 375 | $target = $binding->autowire->alias; |
| 349 | 376 | $ctx = new Ctx(alias: $alias, class: $target, context: $context, singleton: $binding->singleton && $arguments === [] ?: null); |
| 350 | 377 | |
| 351 | - if ($alias === $target) { |
|
| 378 | + if ($alias === $target) |
|
| 379 | + { |
|
| 352 | 380 | $instance = $this->autowire($ctx, \array_merge($binding->autowire->parameters, $arguments), $this, $tracer); |
| 353 | - } else { |
|
| 381 | + } |
|
| 382 | + else |
|
| 383 | + { |
|
| 354 | 384 | $instance = $binding->autowire->resolve($this->factory, $arguments); |
| 355 | 385 | $this->validateConstraint($instance, $ctx); |
| 356 | 386 | } |
@@ -366,25 +396,34 @@ discard block |
||
| 366 | 396 | Tracer $tracer, |
| 367 | 397 | ): mixed { |
| 368 | 398 | $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton && $arguments === [] ?: null); |
| 369 | - try { |
|
| 399 | + try |
|
| 400 | + { |
|
| 370 | 401 | $instance = $binding::class === Config\Factory::class && $binding->getParametersCount() === 0 |
| 371 | 402 | ? ($binding->factory)() |
| 372 | 403 | : $this->invoker->invoke($binding->factory, $arguments); |
| 373 | - } catch (NotCallableException $e) { |
|
| 404 | + } |
|
| 405 | + catch (NotCallableException $e) |
|
| 406 | + { |
|
| 374 | 407 | throw TracedContainerException::createWithTrace( |
| 375 | 408 | \sprintf('Invalid callable binding for `%s`.', $ctx->alias), |
| 376 | 409 | $tracer->getTraces(), |
| 377 | 410 | $e, |
| 378 | 411 | ); |
| 379 | - } catch (TracedContainerException $e) { |
|
| 412 | + } |
|
| 413 | + catch (TracedContainerException $e) |
|
| 414 | + { |
|
| 380 | 415 | throw $e::createWithTrace( |
| 381 | 416 | \sprintf("Can't resolve `%s`: factory invocation failed.", $tracer->getRootAlias()), |
| 382 | 417 | $tracer->getTraces(), |
| 383 | 418 | $e, |
| 384 | 419 | ); |
| 385 | - } catch (ContainerExceptionInterface $e) { |
|
| 420 | + } |
|
| 421 | + catch (ContainerExceptionInterface $e) |
|
| 422 | + { |
|
| 386 | 423 | throw $e; |
| 387 | - } catch (\Throwable $e) { |
|
| 424 | + } |
|
| 425 | + catch (\Throwable $e) |
|
| 426 | + { |
|
| 388 | 427 | throw NotFoundException::createWithTrace( |
| 389 | 428 | \sprintf("Can't resolve `%s` due to factory invocation error: %s", $tracer->getRootAlias(), $e->getMessage()), |
| 390 | 429 | $tracer->getTraces(), |
@@ -392,7 +431,8 @@ discard block |
||
| 392 | 431 | ); |
| 393 | 432 | } |
| 394 | 433 | |
| 395 | - if (\is_object($instance)) { |
|
| 434 | + if (\is_object($instance)) |
|
| 435 | + { |
|
| 396 | 436 | $this->validateConstraint($instance, $ctx); |
| 397 | 437 | return $this->registerInstance($ctx, $instance); |
| 398 | 438 | } |
@@ -409,8 +449,10 @@ discard block |
||
| 409 | 449 | ): ?object { |
| 410 | 450 | $avoidCache = $arguments !== []; |
| 411 | 451 | |
| 412 | - if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) { |
|
| 413 | - try { |
|
| 452 | + if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) |
|
| 453 | + { |
|
| 454 | + try |
|
| 455 | + { |
|
| 414 | 456 | $tracer->push(false, alias: $alias, source: \WeakReference::class, context: $context); |
| 415 | 457 | |
| 416 | 458 | $object = $this->createInstance( |
@@ -419,17 +461,22 @@ discard block |
||
| 419 | 461 | $this, |
| 420 | 462 | $tracer, |
| 421 | 463 | ); |
| 422 | - if ($avoidCache) { |
|
| 464 | + if ($avoidCache) |
|
| 465 | + { |
|
| 423 | 466 | return $object; |
| 424 | 467 | } |
| 425 | 468 | $binding->reference = \WeakReference::create($object); |
| 426 | - } catch (\Throwable) { |
|
| 469 | + } |
|
| 470 | + catch (\Throwable) |
|
| 471 | + { |
|
| 427 | 472 | throw TracedContainerException::createWithTrace(\sprintf( |
| 428 | 473 | 'Can\'t resolve `%s`: can\'t instantiate `%s` from WeakReference binding.', |
| 429 | 474 | $tracer->getRootAlias(), |
| 430 | 475 | $alias, |
| 431 | 476 | ), $tracer->getTraces()); |
| 432 | - } finally { |
|
| 477 | + } |
|
| 478 | + finally |
|
| 479 | + { |
|
| 433 | 480 | $tracer->pop(); |
| 434 | 481 | } |
| 435 | 482 | } |
@@ -445,13 +492,16 @@ discard block |
||
| 445 | 492 | object $instance, |
| 446 | 493 | Ctx $ctx, |
| 447 | 494 | ): void { |
| 448 | - if ($this->options->checkScope) { |
|
| 495 | + if ($this->options->checkScope) |
|
| 496 | + { |
|
| 449 | 497 | // Check scope name |
| 450 | 498 | $ctx->reflection ??= new \ReflectionClass($instance); |
| 451 | 499 | $scopeName = ($ctx->reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
| 452 | - if ($scopeName !== null) { |
|
| 500 | + if ($scopeName !== null) |
|
| 501 | + { |
|
| 453 | 502 | $scope = $this->scope; |
| 454 | - while ($scope->getScopeName() !== $scopeName) { |
|
| 503 | + while ($scope->getScopeName() !== $scopeName) |
|
| 504 | + { |
|
| 455 | 505 | $scope = $scope->getParentScope() ?? throw new BadScopeException($scopeName, $instance::class); |
| 456 | 506 | } |
| 457 | 507 | } |
@@ -478,26 +528,34 @@ discard block |
||
| 478 | 528 | Tracer $tracer, |
| 479 | 529 | ): object { |
| 480 | 530 | $class = $ctx->class; |
| 481 | - try { |
|
| 531 | + try |
|
| 532 | + { |
|
| 482 | 533 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
| 483 | - } catch (\ReflectionException $e) { |
|
| 534 | + } |
|
| 535 | + catch (\ReflectionException $e) |
|
| 536 | + { |
|
| 484 | 537 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 485 | 538 | } |
| 486 | 539 | |
| 487 | 540 | // Check Scope attribute |
| 488 | 541 | $actor = $fallbackActor ?? $this; |
| 489 | - if ($this->options->checkScope) { # todo |
|
| 542 | + if ($this->options->checkScope) |
|
| 543 | + { |
|
| 544 | +# todo |
|
| 490 | 545 | $ar = ($reflection->getAttributes(Attribute\Scope::class)[0] ?? null); |
| 491 | - if ($ar !== null) { |
|
| 546 | + if ($ar !== null) |
|
| 547 | + { |
|
| 492 | 548 | /** @var Attribute\Scope $attr */ |
| 493 | 549 | $attr = $ar->newInstance(); |
| 494 | 550 | $scope = $this->scope; |
| 495 | 551 | $actor = $this; |
| 496 | 552 | // Go through all parent scopes |
| 497 | 553 | $needed = $actor; |
| 498 | - while ($attr->name !== $scope->getScopeName()) { |
|
| 554 | + while ($attr->name !== $scope->getScopeName()) |
|
| 555 | + { |
|
| 499 | 556 | $needed = $scope->getParentActor(); |
| 500 | - if ($needed === null) { |
|
| 557 | + if ($needed === null) |
|
| 558 | + { |
|
| 501 | 559 | throw new BadScopeException($attr->name, $class); |
| 502 | 560 | } |
| 503 | 561 | |
@@ -510,11 +568,13 @@ discard block |
||
| 510 | 568 | } # todo |
| 511 | 569 | |
| 512 | 570 | // We have to construct class using external injector when we know the exact context |
| 513 | - if ($arguments === [] && $actor->binder->hasInjector($class)) { |
|
| 571 | + if ($arguments === [] && $actor->binder->hasInjector($class)) |
|
| 572 | + { |
|
| 514 | 573 | return $actor->resolveInjector($actor->state->bindings[$ctx->class], $ctx, $arguments, $tracer); |
| 515 | 574 | } |
| 516 | 575 | |
| 517 | - if (!$reflection->isInstantiable()) { |
|
| 576 | + if (!$reflection->isInstantiable()) |
|
| 577 | + { |
|
| 518 | 578 | $itIs = match (true) { |
| 519 | 579 | $reflection->isEnum() => 'Enum', |
| 520 | 580 | $reflection->isAbstract() => 'Abstract class', |
@@ -528,8 +588,10 @@ discard block |
||
| 528 | 588 | |
| 529 | 589 | $constructor = $reflection->getConstructor(); |
| 530 | 590 | |
| 531 | - if ($constructor !== null) { |
|
| 532 | - try { |
|
| 591 | + if ($constructor !== null) |
|
| 592 | + { |
|
| 593 | + try |
|
| 594 | + { |
|
| 533 | 595 | $newScope = $this !== $actor; |
| 534 | 596 | $debug = [ |
| 535 | 597 | 'action' => 'resolve arguments', |
@@ -543,7 +605,9 @@ discard block |
||
| 543 | 605 | $tracer->push($newScope, ...$debug); |
| 544 | 606 | $tracer->push(true); |
| 545 | 607 | $args = $actor->resolver->resolveArguments($constructor, $arguments, $actor->options->validateArguments); |
| 546 | - } catch (\Throwable $e) { |
|
| 608 | + } |
|
| 609 | + catch (\Throwable $e) |
|
| 610 | + { |
|
| 547 | 611 | throw TracedContainerException::createWithTrace( |
| 548 | 612 | \sprintf( |
| 549 | 613 | "Can't resolve `%s`.", |
@@ -552,28 +616,39 @@ discard block |
||
| 552 | 616 | $tracer->getTraces(), |
| 553 | 617 | $e, |
| 554 | 618 | ); |
| 555 | - } finally { |
|
| 619 | + } |
|
| 620 | + finally |
|
| 621 | + { |
|
| 556 | 622 | $tracer->pop($newScope); |
| 557 | 623 | $tracer->pop(false); |
| 558 | 624 | } |
| 559 | - try { |
|
| 625 | + try |
|
| 626 | + { |
|
| 560 | 627 | // Using constructor with resolved arguments |
| 561 | 628 | $tracer->push(false, call: "$class::__construct", arguments: $args); |
| 562 | 629 | $tracer->push(true); |
| 563 | 630 | $instance = new $class(...$args); |
| 564 | - } catch (\TypeError $e) { |
|
| 631 | + } |
|
| 632 | + catch (\TypeError $e) |
|
| 633 | + { |
|
| 565 | 634 | throw new WrongTypeException($constructor, $e); |
| 566 | - } catch (TracedContainerException $e) { |
|
| 635 | + } |
|
| 636 | + catch (TracedContainerException $e) |
|
| 637 | + { |
|
| 567 | 638 | throw $e::createWithTrace(\sprintf( |
| 568 | 639 | 'Can\'t resolve `%s`: failed constructing `%s`.', |
| 569 | 640 | $tracer->getRootAlias(), |
| 570 | 641 | $class, |
| 571 | 642 | ), $tracer->getTraces(), $e); |
| 572 | - } finally { |
|
| 643 | + } |
|
| 644 | + finally |
|
| 645 | + { |
|
| 573 | 646 | $tracer->pop(true); |
| 574 | 647 | $tracer->pop(false); |
| 575 | 648 | } |
| 576 | - } else { |
|
| 649 | + } |
|
| 650 | + else |
|
| 651 | + { |
|
| 577 | 652 | // No constructor specified |
| 578 | 653 | $instance = $reflection->newInstance(); |
| 579 | 654 | } |
@@ -605,12 +680,14 @@ discard block |
||
| 605 | 680 | */ |
| 606 | 681 | private function isSingleton(Ctx $ctx): bool |
| 607 | 682 | { |
| 608 | - if (\is_bool($ctx->singleton)) { |
|
| 683 | + if (\is_bool($ctx->singleton)) |
|
| 684 | + { |
|
| 609 | 685 | return $ctx->singleton; |
| 610 | 686 | } |
| 611 | 687 | |
| 612 | 688 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
| 613 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
| 689 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)) |
|
| 690 | + { |
|
| 614 | 691 | return true; |
| 615 | 692 | } |
| 616 | 693 | |
@@ -624,7 +701,8 @@ discard block |
||
| 624 | 701 | * @var Attribute\Finalize|null $attribute |
| 625 | 702 | */ |
| 626 | 703 | $attribute = ($ctx->reflection->getAttributes(Attribute\Finalize::class)[0] ?? null)?->newInstance(); |
| 627 | - if ($attribute === null) { |
|
| 704 | + if ($attribute === null) |
|
| 705 | + { |
|
| 628 | 706 | return null; |
| 629 | 707 | } |
| 630 | 708 | |
@@ -638,10 +716,14 @@ discard block |
||
| 638 | 716 | { |
| 639 | 717 | $scope = $this->scope; |
| 640 | 718 | |
| 641 | - while ($scope !== null) { |
|
| 642 | - foreach ($this->state->inflectors as $class => $inflectors) { |
|
| 643 | - if ($instance instanceof $class) { |
|
| 644 | - foreach ($inflectors as $inflector) { |
|
| 719 | + while ($scope !== null) |
|
| 720 | + { |
|
| 721 | + foreach ($this->state->inflectors as $class => $inflectors) |
|
| 722 | + { |
|
| 723 | + if ($instance instanceof $class) |
|
| 724 | + { |
|
| 725 | + foreach ($inflectors as $inflector) |
|
| 726 | + { |
|
| 645 | 727 | $instance = $inflector->getParametersCount() > 1 |
| 646 | 728 | ? $this->invoker->invoke($inflector->inflector, [$instance]) |
| 647 | 729 | : ($inflector->inflector)($instance); |
@@ -657,9 +739,12 @@ discard block |
||
| 657 | 739 | |
| 658 | 740 | private function validateArguments(ContextFunction $reflection, array $arguments = []): bool |
| 659 | 741 | { |
| 660 | - try { |
|
| 742 | + try |
|
| 743 | + { |
|
| 661 | 744 | $this->resolver->validateArguments($reflection, $arguments); |
| 662 | - } catch (\Throwable) { |
|
| 745 | + } |
|
| 746 | + catch (\Throwable) |
|
| 747 | + { |
|
| 663 | 748 | return false; |
| 664 | 749 | } |
| 665 | 750 | |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | { |
| 26 | 26 | $result = []; |
| 27 | 27 | $i = 0; |
| 28 | - foreach ($blocks as $block) { |
|
| 28 | + foreach ($blocks as $block){ |
|
| 29 | 29 | \array_push($result, ...self::blockToStringList($block, $i++)); |
| 30 | 30 | } |
| 31 | 31 | return \implode("\n", $result); |
@@ -47,19 +47,19 @@ discard block |
||
| 47 | 47 | public function push(bool $nextLevel, mixed ...$details): void |
| 48 | 48 | { |
| 49 | 49 | $trace = $details === [] ? null : new Trace($details); |
| 50 | - if ($nextLevel || $this->traces === []) { |
|
| 50 | + if ($nextLevel || $this->traces === []){ |
|
| 51 | 51 | $this->traces[] = $trace === null ? [] : [$trace]; |
| 52 | - } elseif ($trace !== null) { |
|
| 52 | + } elseif ($trace !== null){ |
|
| 53 | 53 | $this->traces[\array_key_last($this->traces)][] = $trace; |
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | public function pop(bool $previousLevel = false): void |
| 58 | 58 | { |
| 59 | - if ($this->traces === []) { |
|
| 59 | + if ($this->traces === []){ |
|
| 60 | 60 | return; |
| 61 | 61 | } |
| 62 | - if ($previousLevel) { |
|
| 62 | + if ($previousLevel){ |
|
| 63 | 63 | \array_pop($this->traces); |
| 64 | 64 | return; |
| 65 | 65 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | public function __toString(): string |
| 77 | 77 | { |
| 78 | - return $this->traces === [] ? '' : "Resolving trace:\n" . self::renderTraceList($this->traces); |
|
| 78 | + return $this->traces === [] ? '' : "Resolving trace:\n".self::renderTraceList($this->traces); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | // Separator |
| 93 | 93 | $s = "\n"; |
| 94 | 94 | $nexPrefix = "$s$padding "; |
| 95 | - foreach ($items as $item) { |
|
| 96 | - $result[] = $firstPrefix . \str_replace($s, $nexPrefix, (string) $item); |
|
| 95 | + foreach ($items as $item){ |
|
| 96 | + $result[] = $firstPrefix.\str_replace($s, $nexPrefix, (string)$item); |
|
| 97 | 97 | } |
| 98 | 98 | return $result; |
| 99 | 99 | } |
@@ -25,7 +25,8 @@ discard block |
||
| 25 | 25 | { |
| 26 | 26 | $result = []; |
| 27 | 27 | $i = 0; |
| 28 | - foreach ($blocks as $block) { |
|
| 28 | + foreach ($blocks as $block) |
|
| 29 | + { |
|
| 29 | 30 | \array_push($result, ...self::blockToStringList($block, $i++)); |
| 30 | 31 | } |
| 31 | 32 | return \implode("\n", $result); |
@@ -47,19 +48,24 @@ discard block |
||
| 47 | 48 | public function push(bool $nextLevel, mixed ...$details): void |
| 48 | 49 | { |
| 49 | 50 | $trace = $details === [] ? null : new Trace($details); |
| 50 | - if ($nextLevel || $this->traces === []) { |
|
| 51 | + if ($nextLevel || $this->traces === []) |
|
| 52 | + { |
|
| 51 | 53 | $this->traces[] = $trace === null ? [] : [$trace]; |
| 52 | - } elseif ($trace !== null) { |
|
| 54 | + } |
|
| 55 | + elseif ($trace !== null) |
|
| 56 | + { |
|
| 53 | 57 | $this->traces[\array_key_last($this->traces)][] = $trace; |
| 54 | 58 | } |
| 55 | 59 | } |
| 56 | 60 | |
| 57 | 61 | public function pop(bool $previousLevel = false): void |
| 58 | 62 | { |
| 59 | - if ($this->traces === []) { |
|
| 63 | + if ($this->traces === []) |
|
| 64 | + { |
|
| 60 | 65 | return; |
| 61 | 66 | } |
| 62 | - if ($previousLevel) { |
|
| 67 | + if ($previousLevel) |
|
| 68 | + { |
|
| 63 | 69 | \array_pop($this->traces); |
| 64 | 70 | return; |
| 65 | 71 | } |
@@ -92,7 +98,8 @@ discard block |
||
| 92 | 98 | // Separator |
| 93 | 99 | $s = "\n"; |
| 94 | 100 | $nexPrefix = "$s$padding "; |
| 95 | - foreach ($items as $item) { |
|
| 101 | + foreach ($items as $item) |
|
| 102 | + { |
|
| 96 | 103 | $result[] = $firstPrefix . \str_replace($s, $nexPrefix, (string) $item); |
| 97 | 104 | } |
| 98 | 105 | return $result; |
@@ -27,29 +27,29 @@ discard block |
||
| 27 | 27 | MagicCallTrait::class, |
| 28 | 28 | ] : []; |
| 29 | 29 | |
| 30 | - if (\str_contains($className, '\\')) { |
|
| 30 | + if (\str_contains($className, '\\')){ |
|
| 31 | 31 | $classShortName = \substr($className, \strrpos($className, '\\') + 1); |
| 32 | - $classNamespaceStr = 'namespace ' . \substr($className, 0, \strrpos($className, '\\')) . ';'; |
|
| 33 | - } else { |
|
| 32 | + $classNamespaceStr = 'namespace '.\substr($className, 0, \strrpos($className, '\\')).';'; |
|
| 33 | + }else{ |
|
| 34 | 34 | $classShortName = $className; |
| 35 | 35 | $classNamespaceStr = ''; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | $interface = $type->getName(); |
| 39 | 39 | $classBody = []; |
| 40 | - foreach ($type->getMethods() as $method) { |
|
| 41 | - if ($method->isConstructor()) { |
|
| 40 | + foreach ($type->getMethods() as $method){ |
|
| 41 | + if ($method->isConstructor()){ |
|
| 42 | 42 | throw new \LogicException('Constructor is not allowed in a proxy.'); |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - if ($method->isDestructor()) { |
|
| 45 | + if ($method->isDestructor()){ |
|
| 46 | 46 | $classBody[] = self::renderMethod($method); |
| 47 | 47 | continue; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | $hasRefs = false; |
| 51 | - $return = $method->hasReturnType() && (string) $method->getReturnType() === 'void' ? '' : 'return '; |
|
| 52 | - $call = ($method->isStatic() ? '::' : '->') . $method->getName(); |
|
| 51 | + $return = $method->hasReturnType() && (string)$method->getReturnType() === 'void' ? '' : 'return '; |
|
| 52 | + $call = ($method->isStatic() ? '::' : '->').$method->getName(); |
|
| 53 | 53 | $context = $method->isStatic() ? 'null' : '$this->__container_proxy_context'; |
| 54 | 54 | $containerStr = match (false) { |
| 55 | 55 | $attachContainer => 'null', |
@@ -69,12 +69,12 @@ discard block |
||
| 69 | 69 | PHP; |
| 70 | 70 | |
| 71 | 71 | $args = []; |
| 72 | - foreach ($method->getParameters() as $param) { |
|
| 72 | + foreach ($method->getParameters() as $param){ |
|
| 73 | 73 | $hasRefs = $hasRefs || $param->isPassedByReference(); |
| 74 | - $args[] = ($param->isVariadic() ? '...' : '') . '$' . $param->getName(); |
|
| 74 | + $args[] = ($param->isVariadic() ? '...' : '').'$'.$param->getName(); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - if (!$hasRefs && !$method->isVariadic()) { |
|
| 77 | + if (!$hasRefs && !$method->isVariadic()){ |
|
| 78 | 78 | $classBody[] = self::renderMethod( |
| 79 | 79 | $method, |
| 80 | 80 | <<<PHP |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | $argsStr = \implode(', ', $args); |
| 88 | 88 | |
| 89 | - if ($method->isVariadic()) { |
|
| 89 | + if ($method->isVariadic()){ |
|
| 90 | 90 | $classBody[] = self::renderMethod( |
| 91 | 91 | $method, |
| 92 | 92 | <<<PHP |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | $traitsStr = $traits === [] ? '' : \implode( |
| 110 | 110 | "\n ", |
| 111 | - \array_map(static fn(string $trait): string => 'use \\' . \ltrim($trait, '\\') . ';', $traits), |
|
| 111 | + \array_map(static fn(string $trait) : string => 'use \\'.\ltrim($trait, '\\').';', $traits), |
|
| 112 | 112 | ); |
| 113 | 113 | return <<<PHP |
| 114 | 114 | $classNamespaceStr |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | $m->getName(), |
| 132 | 132 | \implode(', ', \array_map(self::renderParameter(...), $m->getParameters())), |
| 133 | 133 | $m->hasReturnType() |
| 134 | - ? ': ' . self::renderParameterTypes($m->getReturnType(), $m->getDeclaringClass()) |
|
| 134 | + ? ': '.self::renderParameterTypes($m->getReturnType(), $m->getDeclaringClass()) |
|
| 135 | 135 | : '', |
| 136 | 136 | $body, |
| 137 | 137 | ); |
@@ -145,8 +145,8 @@ discard block |
||
| 145 | 145 | $param->hasType() ? 'mixed' : '', |
| 146 | 146 | $param->isPassedByReference() ? '&' : '', |
| 147 | 147 | $param->isVariadic() ? '...' : '', |
| 148 | - '$' . $param->getName(), |
|
| 149 | - $param->isOptional() && !$param->isVariadic() ? ' = ' . self::renderDefaultValue($param) : '', |
|
| 148 | + '$'.$param->getName(), |
|
| 149 | + $param->isOptional() && !$param->isVariadic() ? ' = '.self::renderDefaultValue($param) : '', |
|
| 150 | 150 | ), |
| 151 | 151 | ' ', |
| 152 | 152 | ); |
@@ -154,8 +154,8 @@ discard block |
||
| 154 | 154 | |
| 155 | 155 | public static function renderParameterTypes(\ReflectionType $types, \ReflectionClass $class): string |
| 156 | 156 | { |
| 157 | - if ($types instanceof \ReflectionNamedType) { |
|
| 158 | - return ($types->allowsNull() && $types->getName() !== 'mixed' ? '?' : '') . ($types->isBuiltin() |
|
| 157 | + if ($types instanceof \ReflectionNamedType){ |
|
| 158 | + return ($types->allowsNull() && $types->getName() !== 'mixed' ? '?' : '').($types->isBuiltin() |
|
| 159 | 159 | ? $types->getName() |
| 160 | 160 | : self::normalizeClassType($types, $class)); |
| 161 | 161 | } |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | }; |
| 168 | 168 | |
| 169 | 169 | $result = []; |
| 170 | - foreach ($types as $type) { |
|
| 170 | + foreach ($types as $type){ |
|
| 171 | 171 | $result[] = $type->isBuiltin() |
| 172 | 172 | ? $type->getName() |
| 173 | 173 | : self::normalizeClassType($type, $class); |
@@ -178,12 +178,12 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | public static function renderDefaultValue(\ReflectionParameter $param): string |
| 180 | 180 | { |
| 181 | - if ($param->isDefaultValueConstant()) { |
|
| 181 | + if ($param->isDefaultValueConstant()){ |
|
| 182 | 182 | $result = $param->getDefaultValueConstantName(); |
| 183 | 183 | |
| 184 | - return \explode('::', (string) $result)[0] === 'self' |
|
| 184 | + return \explode('::', (string)$result)[0] === 'self' |
|
| 185 | 185 | ? $result |
| 186 | - : '\\' . $result; |
|
| 186 | + : '\\'.$result; |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | $cut = self::cutDefaultValue($param); |
@@ -197,14 +197,14 @@ discard block |
||
| 197 | 197 | { |
| 198 | 198 | return match ($type->getName()) { |
| 199 | 199 | 'static' => 'static', |
| 200 | - 'self' => '\\' . $class->getName(), |
|
| 201 | - default => '\\' . $type->getName(), |
|
| 200 | + 'self' => '\\'.$class->getName(), |
|
| 201 | + default => '\\'.$type->getName(), |
|
| 202 | 202 | }; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | private static function cutDefaultValue(\ReflectionParameter $param): string |
| 206 | 206 | { |
| 207 | - $string = (string) $param; |
|
| 207 | + $string = (string)$param; |
|
| 208 | 208 | |
| 209 | 209 | return \trim(\substr($string, \strpos($string, '=') + 1, -1)); |
| 210 | 210 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | final class QueueableDetector |
| 11 | 11 | { |
| 12 | - public function __construct(private readonly ReaderInterface $reader) {} |
|
| 12 | + public function __construct(private readonly ReaderInterface $reader){} |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * @param class-string|object $object |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | $reflection = new \ReflectionClass($object); |
| 20 | 20 | |
| 21 | 21 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
| 22 | - if ($reflection->implementsInterface(QueueableInterface::class)) { |
|
| 22 | + if ($reflection->implementsInterface(QueueableInterface::class)){ |
|
| 23 | 23 | return true; |
| 24 | 24 | } |
| 25 | 25 | |
@@ -34,11 +34,11 @@ discard block |
||
| 34 | 34 | $reflection = new \ReflectionClass($object); |
| 35 | 35 | |
| 36 | 36 | $attribute = $this->reader->firstClassMetadata($reflection, Queueable::class); |
| 37 | - if ($attribute !== null) { |
|
| 37 | + if ($attribute !== null){ |
|
| 38 | 38 | return $attribute->queue; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - if (\is_object($object) && $reflection->hasMethod('getQueue')) { |
|
| 41 | + if (\is_object($object) && $reflection->hasMethod('getQueue')){ |
|
| 42 | 42 | return $reflection->getMethod('getQueue')->invoke($object); |
| 43 | 43 | } |
| 44 | 44 | |
@@ -9,7 +9,9 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | final class QueueableDetector |
| 11 | 11 | { |
| 12 | - public function __construct(private readonly ReaderInterface $reader) {} |
|
| 12 | + public function __construct(private readonly ReaderInterface $reader) |
|
| 13 | + { |
|
| 14 | +} |
|
| 13 | 15 | |
| 14 | 16 | /** |
| 15 | 17 | * @param class-string|object $object |
@@ -19,7 +21,8 @@ discard block |
||
| 19 | 21 | $reflection = new \ReflectionClass($object); |
| 20 | 22 | |
| 21 | 23 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
| 22 | - if ($reflection->implementsInterface(QueueableInterface::class)) { |
|
| 24 | + if ($reflection->implementsInterface(QueueableInterface::class)) |
|
| 25 | + { |
|
| 23 | 26 | return true; |
| 24 | 27 | } |
| 25 | 28 | |
@@ -34,11 +37,13 @@ discard block |
||
| 34 | 37 | $reflection = new \ReflectionClass($object); |
| 35 | 38 | |
| 36 | 39 | $attribute = $this->reader->firstClassMetadata($reflection, Queueable::class); |
| 37 | - if ($attribute !== null) { |
|
| 40 | + if ($attribute !== null) |
|
| 41 | + { |
|
| 38 | 42 | return $attribute->queue; |
| 39 | 43 | } |
| 40 | 44 | |
| 41 | - if (\is_object($object) && $reflection->hasMethod('getQueue')) { |
|
| 45 | + if (\is_object($object) && $reflection->hasMethod('getQueue')) |
|
| 46 | + { |
|
| 42 | 47 | return $reflection->getMethod('getQueue')->invoke($object); |
| 43 | 48 | } |
| 44 | 49 | |