From abd51747a8da29541a46fab82b993507176b6aeb Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 25 Feb 2026 21:27:28 +0700 Subject: [PATCH 1/5] [DX] Define list of allowed implicit commands on ConsoleApplication --- src/Console/ConsoleApplication.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Console/ConsoleApplication.php b/src/Console/ConsoleApplication.php index 8b637b16f14..e65afcf4812 100644 --- a/src/Console/ConsoleApplication.php +++ b/src/Console/ConsoleApplication.php @@ -22,6 +22,16 @@ final class ConsoleApplication extends Application { private const string NAME = 'Rector'; + private const ALLOWED_COMMANDS = [ + 'custom-rule', + 'process', + 'list', + 'setup-ci', + 'worker', + 'help', + 'completion', + ]; + /** * @param Command[] $commands */ @@ -73,6 +83,8 @@ public function doRun(InputInterface $input, OutputInterface $output): int $tokens = $privatesAccessor->getPrivateProperty($input, 'tokens'); $tokens = array_merge(['process'], $tokens); $privatesAccessor->setPrivateProperty($input, 'tokens', $tokens); + } elseif (! in_array($commandName, self::ALLOWED_COMMANDS, true)) { + Assert::fileExists($commandName); } return parent::doRun($input, $output); From dffed59729d54e47519431f050ecacdec1ad25eb Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Wed, 25 Feb 2026 14:31:22 +0000 Subject: [PATCH 2/5] [ci-review] Rector Rectify --- src/Console/ConsoleApplication.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/ConsoleApplication.php b/src/Console/ConsoleApplication.php index e65afcf4812..7ce079001de 100644 --- a/src/Console/ConsoleApplication.php +++ b/src/Console/ConsoleApplication.php @@ -22,7 +22,7 @@ final class ConsoleApplication extends Application { private const string NAME = 'Rector'; - private const ALLOWED_COMMANDS = [ + private const array ALLOWED_COMMANDS = [ 'custom-rule', 'process', 'list', From df44c882e692665fe8baa83e8c57294c691cc20b Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 25 Feb 2026 21:33:27 +0700 Subject: [PATCH 3/5] fix null command --- src/Console/ConsoleApplication.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Console/ConsoleApplication.php b/src/Console/ConsoleApplication.php index 7ce079001de..e94461917aa 100644 --- a/src/Console/ConsoleApplication.php +++ b/src/Console/ConsoleApplication.php @@ -23,6 +23,10 @@ final class ConsoleApplication extends Application private const string NAME = 'Rector'; private const array ALLOWED_COMMANDS = [ + // null is for example: bin/rector --version + null, + + // default commands 'custom-rule', 'process', 'list', From a44f1d54f8ebb3ff552ccf21f3ee760b3d17addf Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 25 Feb 2026 21:35:37 +0700 Subject: [PATCH 4/5] define array docblock --- src/Console/ConsoleApplication.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Console/ConsoleApplication.php b/src/Console/ConsoleApplication.php index e94461917aa..7dc98edad30 100644 --- a/src/Console/ConsoleApplication.php +++ b/src/Console/ConsoleApplication.php @@ -22,6 +22,9 @@ final class ConsoleApplication extends Application { private const string NAME = 'Rector'; + /** + * @var array + */ private const array ALLOWED_COMMANDS = [ // null is for example: bin/rector --version null, From 4f85941a1cf6bb5b7619fc3f020c2030738fa03f Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 25 Feb 2026 21:44:47 +0700 Subject: [PATCH 5/5] fix exit code --- src/Console/ConsoleApplication.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Console/ConsoleApplication.php b/src/Console/ConsoleApplication.php index 7dc98edad30..c17866b6e36 100644 --- a/src/Console/ConsoleApplication.php +++ b/src/Console/ConsoleApplication.php @@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Style\SymfonyStyle; use Webmozart\Assert\Assert; final class ConsoleApplication extends Application @@ -42,7 +43,7 @@ final class ConsoleApplication extends Application /** * @param Command[] $commands */ - public function __construct(array $commands) + public function __construct(array $commands, private readonly SymfonyStyle $symfonyStyle) { parent::__construct(self::NAME, VersionResolver::PACKAGE_VERSION); @@ -91,7 +92,15 @@ public function doRun(InputInterface $input, OutputInterface $output): int $tokens = array_merge(['process'], $tokens); $privatesAccessor->setPrivateProperty($input, 'tokens', $tokens); } elseif (! in_array($commandName, self::ALLOWED_COMMANDS, true)) { - Assert::fileExists($commandName); + $this->symfonyStyle->error( + sprintf( + 'The following given path does not match any files or directories: %s%s', + "\n\n - ", + $commandName + ) + ); + + return ExitCode::FAILURE; } return parent::doRun($input, $output);