|
1 | 1 | <?php |
2 | 2 |
|
3 | 3 | /** @noinspection EfferentObjectCouplingInspection */ |
| 4 | +/** @noinspection PhpUnused */ |
4 | 5 |
|
5 | 6 | declare(strict_types=1); |
6 | 7 |
|
|
24 | 25 | use Rector\DependencyInjection\LazyContainerFactory; |
25 | 26 | use Symfony\Component\Console\Application; |
26 | 27 | use Symfony\Component\Console\Input\ArgvInput; |
| 28 | +use Symfony\Component\Console\Input\InputDefinition; |
27 | 29 | use Symfony\Component\Console\Input\InputInterface; |
28 | 30 | use Symfony\Component\Console\Output\ConsoleOutput; |
29 | 31 | use Symfony\Component\Console\Output\OutputInterface; |
|
39 | 41 | */ |
40 | 42 | final class ComposerScripts |
41 | 43 | { |
| 44 | + /** |
| 45 | + * @see \PhpCsFixer\Hasher |
| 46 | + * @see \PhpCsFixer\Utils |
| 47 | + */ |
| 48 | + private function __construct() {} |
| 49 | + |
42 | 50 | /** |
43 | 51 | * @see \Composer\Util\Silencer |
44 | 52 | * |
@@ -126,7 +134,6 @@ public static function dumpSoarPHPConfig(Event $event): int |
126 | 134 | /** |
127 | 135 | * @throws \Guanguans\SoarPHP\Exceptions\InvalidOptionException |
128 | 136 | * |
129 | | - * @noinspection D |
130 | 137 | * @noinspection PhpFunctionCyclomaticComplexityInspection |
131 | 138 | */ |
132 | 139 | public static function resolveSoarHelp(): Collection |
@@ -249,41 +256,79 @@ public static function makeRectorConfig(): RectorConfig |
249 | 256 | return $rectorConfig ??= (new LazyContainerFactory)->create(); |
250 | 257 | } |
251 | 258 |
|
| 259 | + /** |
| 260 | + * @noinspection PhpPossiblePolymorphicInvocationInspection |
| 261 | + */ |
| 262 | + public static function requireAutoload(Event $event, ?bool $enableDebugging = null): void |
| 263 | + { |
| 264 | + $enableDebugging ??= (new ArgvInput)->hasParameterOption('-vvv', true); |
| 265 | + $enableDebugging and $event->getIO()->enableDebugging(microtime(true)); |
| 266 | + (fn () => $this->output->setVerbosity(OutputInterface::VERBOSITY_DEBUG))->call($event->getIO()); |
| 267 | + |
| 268 | + require_once $event->getComposer()->getConfig()->get('vendor-dir').\DIRECTORY_SEPARATOR.'autoload.php'; |
| 269 | + } |
| 270 | + |
| 271 | + /** |
| 272 | + * @param null|list<string> $argv |
| 273 | + */ |
| 274 | + public static function makeArgvInput(?array $argv = null, ?InputDefinition $inputDefinition = null): ArgvInput |
| 275 | + { |
| 276 | + static $argvInput; |
| 277 | + |
| 278 | + return $argvInput ??= new ArgvInput($argv, $inputDefinition); |
| 279 | + } |
| 280 | + |
252 | 281 | /** |
253 | 282 | * @see \Rector\Console\Style\SymfonyStyleFactory |
254 | 283 | */ |
255 | | - public static function makeSymfonyStyle(): SymfonyStyle |
| 284 | + public static function makeSymfonyStyle(?InputInterface $input = null, ?OutputInterface $output = null): SymfonyStyle |
256 | 285 | { |
257 | 286 | static $symfonyStyle; |
258 | 287 |
|
259 | | - if ($symfonyStyle instanceof SymfonyStyle) { |
| 288 | + if ( |
| 289 | + $symfonyStyle instanceof SymfonyStyle |
| 290 | + && ( |
| 291 | + !$input instanceof InputInterface |
| 292 | + || (string) \Closure::bind( |
| 293 | + static fn (SymfonyStyle $symfonyStyle): InputInterface => $symfonyStyle->input, |
| 294 | + null, |
| 295 | + SymfonyStyle::class |
| 296 | + )($symfonyStyle) === (string) $input |
| 297 | + ) |
| 298 | + && ( |
| 299 | + !$output instanceof OutputInterface |
| 300 | + || \Closure::bind( |
| 301 | + static fn (SymfonyStyle $symfonyStyle): OutputInterface => $symfonyStyle->output, |
| 302 | + null, |
| 303 | + SymfonyStyle::class |
| 304 | + )($symfonyStyle) === $output |
| 305 | + ) |
| 306 | + ) { |
260 | 307 | return $symfonyStyle; |
261 | 308 | } |
262 | 309 |
|
263 | | - $argvInput = new ArgvInput; |
264 | | - $consoleOutput = new ConsoleOutput; |
| 310 | + $input ??= new ArgvInput; |
| 311 | + $output ??= new ConsoleOutput; |
265 | 312 |
|
266 | 313 | // to configure all -v, -vv, -vvv options without memory-lock to Application run() arguments |
267 | | - (fn () => $this->configureIO($argvInput, $consoleOutput))->call(new Application); |
| 314 | + (fn () => $this->configureIO($input, $output))->call(new Application); |
| 315 | + |
| 316 | + // --debug or --xdebug is called |
| 317 | + if ($input->hasParameterOption(['--debug', '--xdebug'], true)) { |
| 318 | + $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG); |
| 319 | + } |
268 | 320 |
|
269 | | - // --debug is called |
270 | | - if ($argvInput->hasParameterOption(['--debug', '--xdebug'], true)) { |
271 | | - $consoleOutput->setVerbosity(OutputInterface::VERBOSITY_DEBUG); |
| 321 | + // disable output for testing |
| 322 | + if (self::isRunningInTesting()) { |
| 323 | + $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); |
272 | 324 | } |
273 | 325 |
|
274 | | - return $symfonyStyle = new SymfonyStyle($argvInput, $consoleOutput); |
| 326 | + return $symfonyStyle = new SymfonyStyle($input, $output); |
275 | 327 | } |
276 | 328 |
|
277 | | - /** |
278 | | - * @noinspection PhpPossiblePolymorphicInvocationInspection |
279 | | - */ |
280 | | - private static function requireAutoload(Event $event, ?bool $enableDebugging = null): void |
| 329 | + public static function isRunningInTesting(): bool |
281 | 330 | { |
282 | | - $enableDebugging ??= (new ArgvInput)->hasParameterOption('-vvv', true); |
283 | | - $enableDebugging and $event->getIO()->enableDebugging(microtime(true)); |
284 | | - (fn () => $this->output->setVerbosity(OutputInterface::VERBOSITY_DEBUG))->call($event->getIO()); |
285 | | - |
286 | | - require_once $event->getComposer()->getConfig()->get('vendor-dir').\DIRECTORY_SEPARATOR.'autoload.php'; |
| 331 | + return 'testing' === getenv('ENV'); |
287 | 332 | } |
288 | 333 |
|
289 | 334 | /** |
|
0 commit comments