From 98c4f6a06ce6b04e17b72329522868d9646ce3dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Sch=C3=A4dlich?= Date: Mon, 30 Sep 2019 20:52:02 +0200 Subject: [PATCH] [Console] Command::execute() should always return int - deprecate returning null - added deprecation message for non-int return value in Command::execute() - fixed all core commands to return proper int values - added proper return type-hint to Command::execute() method in all core Commands --- UPGRADE-4.4.md | 1 + UPGRADE-5.0.md | 1 + src/Symfony/Bridge/Twig/Command/DebugCommand.php | 8 ++++++-- .../FrameworkBundle/Command/AboutCommand.php | 4 +++- .../FrameworkBundle/Command/CacheClearCommand.php | 4 +++- .../Command/CachePoolClearCommand.php | 4 +++- .../Command/CachePoolDeleteCommand.php | 6 ++++-- .../Command/CachePoolListCommand.php | 4 +++- .../Command/CachePoolPruneCommand.php | 4 +++- .../FrameworkBundle/Command/CacheWarmupCommand.php | 4 +++- .../FrameworkBundle/Command/ConfigDebugCommand.php | 8 +++++--- .../Command/ContainerDebugCommand.php | 4 +++- .../Command/EventDispatcherDebugCommand.php | 6 ++++-- .../FrameworkBundle/Command/RouterDebugCommand.php | 4 +++- .../Command/TranslationDebugCommand.php | 6 ++++-- .../Command/WorkflowDumpCommand.php | 4 +++- .../WebServerBundle/Command/ServerLogCommand.php | 2 ++ .../WebServerBundle/Command/ServerStartCommand.php | 2 +- .../Command/ServerStatusCommand.php | 2 +- .../WebServerBundle/Command/ServerStopCommand.php | 2 +- src/Symfony/Component/Console/CHANGELOG.md | 1 + src/Symfony/Component/Console/Command/Command.php | 6 +++++- .../Component/Console/Command/HelpCommand.php | 2 ++ .../Component/Console/Command/ListCommand.php | 2 ++ .../Component/Console/Tests/ApplicationTest.php | 4 +++- .../Console/Tests/Command/CommandTest.php | 14 -------------- .../Console/Tests/Fixtures/BarHiddenCommand.php | 3 ++- .../Console/Tests/Fixtures/Foo1Command.php | 4 +++- .../Console/Tests/Fixtures/Foo2Command.php | 3 ++- .../Console/Tests/Fixtures/Foo3Command.php | 4 +++- .../Console/Tests/Fixtures/FooCommand.php | 4 +++- .../Console/Tests/Fixtures/FooHiddenCommand.php | 3 ++- .../Console/Tests/Fixtures/FooOptCommand.php | 4 +++- .../Tests/Fixtures/FooSubnamespaced1Command.php | 4 +++- .../Tests/Fixtures/FooSubnamespaced2Command.php | 4 +++- .../Tests/Fixtures/FooWithoutAliasCommand.php | 4 +++- .../Console/Tests/Fixtures/FoobarCommand.php | 4 +++- .../Fixtures/TestAmbiguousCommandRegistering.php | 4 +++- .../Fixtures/TestAmbiguousCommandRegistering2.php | 4 +++- .../Console/Tests/Fixtures/TestCommand.php | 2 ++ .../ErrorRenderer/Command/DebugCommand.php | 2 ++ .../Component/Form/Command/DebugCommand.php | 2 ++ .../Messenger/Command/ConsumeMessagesCommand.php | 2 ++ .../Component/Messenger/Command/DebugCommand.php | 2 ++ .../Command/FailedMessagesRemoveCommand.php | 2 ++ .../Command/FailedMessagesRetryCommand.php | 4 +++- .../Command/FailedMessagesShowCommand.php | 2 ++ .../Messenger/Command/SetupTransportsCommand.php | 2 ++ .../Messenger/Command/StopWorkersCommand.php | 2 ++ .../VarDumper/Command/ServerDumpCommand.php | 2 +- 50 files changed, 128 insertions(+), 54 deletions(-) diff --git a/UPGRADE-4.4.md b/UPGRADE-4.4.md index 63456df5a9d5..5f08a1599b08 100644 --- a/UPGRADE-4.4.md +++ b/UPGRADE-4.4.md @@ -10,6 +10,7 @@ Console ------- * Deprecated finding hidden commands using an abbreviation, use the full name instead + * Deprecated returning `null` from `Command::execute()`, return `0` instead Debug ----- diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 52bccb7f24f0..ab1af5848978 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -37,6 +37,7 @@ Console * Removed the `getHorizontalBorderChar()` method in favor of the `getBorderChars()` method in `TableStyle`. * Removed the `setVerticalBorderChar()` method in favor of the `setVerticalBorderChars()` method in `TableStyle`. * Removed the `getVerticalBorderChar()` method in favor of the `getBorderChars()` method in `TableStyle`. + * Removed support for returning `null` from `Command::execute()`, return `0` instead * The `ProcessHelper::run()` method takes the command as an array of arguments. Before: diff --git a/src/Symfony/Bridge/Twig/Command/DebugCommand.php b/src/Symfony/Bridge/Twig/Command/DebugCommand.php index 7a6ef63609a2..b3a2c44df313 100644 --- a/src/Symfony/Bridge/Twig/Command/DebugCommand.php +++ b/src/Symfony/Bridge/Twig/Command/DebugCommand.php @@ -111,12 +111,16 @@ protected function execute(InputInterface $input, OutputInterface $output) switch ($input->getOption('format')) { case 'text': - return $name ? $this->displayPathsText($io, $name) : $this->displayGeneralText($io, $filter); + $name ? $this->displayPathsText($io, $name) : $this->displayGeneralText($io, $filter); + break; case 'json': - return $name ? $this->displayPathsJson($io, $name) : $this->displayGeneralJson($io, $filter); + $name ? $this->displayPathsJson($io, $name) : $this->displayGeneralJson($io, $filter); + break; default: throw new InvalidArgumentException(sprintf('The format "%s" is not supported.', $input->getOption('format'))); } + + return 0; } private function displayPathsText(SymfonyStyle $io, string $name) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php index cf3e946f6a6a..0ca4172de407 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php @@ -54,7 +54,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); @@ -100,6 +100,8 @@ protected function execute(InputInterface $input, OutputInterface $output) } $io->table([], $rows); + + return 0; } private static function formatPath(string $path, string $baseDir): string diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php index 24aa8171ca5e..6711e456b10a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php @@ -72,7 +72,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $fs = $this->filesystem; $io = new SymfonyStyle($input, $output); @@ -175,6 +175,8 @@ protected function execute(InputInterface $input, OutputInterface $output) } $io->success(sprintf('Cache for the "%s" environment (debug=%s) was successfully cleared.', $kernel->getEnvironment(), var_export($kernel->isDebug(), true))); + + return 0; } private function warmup(string $warmupDir, string $realCacheDir, bool $enableOptionalWarmers = true) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CachePoolClearCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CachePoolClearCommand.php index dc42910d3432..50aacd9bbd73 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CachePoolClearCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CachePoolClearCommand.php @@ -60,7 +60,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $kernel = $this->getApplication()->getKernel(); @@ -99,5 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $io->success('Cache was successfully cleared.'); + + return 0; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CachePoolDeleteCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CachePoolDeleteCommand.php index 656f9a9de302..2a7a2fe51304 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CachePoolDeleteCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CachePoolDeleteCommand.php @@ -59,7 +59,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $pool = $input->getArgument('pool'); @@ -69,7 +69,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if (!$cachePool->hasItem($key)) { $io->note(sprintf('Cache item "%s" does not exist in cache pool "%s".', $key, $pool)); - return; + return 0; } if (!$cachePool->deleteItem($key)) { @@ -77,5 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $io->success(sprintf('Cache item "%s" was successfully deleted.', $key)); + + return 0; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CachePoolListCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CachePoolListCommand.php index 4f399ab61556..7b725411d501 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CachePoolListCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CachePoolListCommand.php @@ -51,12 +51,14 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $io->table(['Pool name'], array_map(function ($pool) { return [$pool]; }, $this->poolNames)); + + return 0; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CachePoolPruneCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CachePoolPruneCommand.php index 74b53063784b..65f3ff6b5802 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CachePoolPruneCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CachePoolPruneCommand.php @@ -57,7 +57,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); @@ -67,5 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $io->success('Successfully pruned cache pool(s).'); + + return 0; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php index 04b5d2f7c6b9..0a87acf26419 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php @@ -66,7 +66,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); @@ -80,5 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->cacheWarmer->warmUp($kernel->getContainer()->getParameter('kernel.cache_dir')); $io->success(sprintf('Cache for the "%s" environment (debug=%s) was successfully warmed.', $kernel->getEnvironment(), var_export($kernel->isDebug(), true))); + + return 0; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php index faadcb96b3ae..2aa631eb76e4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php @@ -63,7 +63,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $errorIo = $io->getErrorStyle(); @@ -73,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $errorIo->comment('Provide the name of a bundle as the first argument of this command to dump its configuration. (e.g. debug:config FrameworkBundle)'); $errorIo->comment('For dumping a specific option, add its path as the second argument of this command. (e.g. debug:config FrameworkBundle serializer to dump the framework.serializer configuration)'); - return; + return 0; } $extension = $this->findExtension($name); @@ -101,7 +101,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $io->writeln(Yaml::dump([$extensionAlias => $config], 10)); - return; + return 0; } try { @@ -115,6 +115,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $io->title(sprintf('Current configuration for "%s.%s"', $extensionAlias, $path)); $io->writeln(Yaml::dump($config, 10)); + + return 0; } private function compileContainer(): ContainerBuilder diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php index dc8ea90ab4eb..ef3a70d33ef1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php @@ -114,7 +114,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { if ($input->getOption('show-private')) { @trigger_error('The "--show-private" option no longer has any effect and is deprecated since Symfony 4.1.', E_USER_DEPRECATED); @@ -184,6 +184,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $errorIo->comment('To search for a specific service, re-run this command with a search term. (e.g. debug:container log)'); } } + + return 0; } /** diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php index e61f543e7f78..ad49cdeeaa87 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php @@ -69,7 +69,7 @@ protected function configure() * * @throws \LogicException */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); @@ -78,7 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if (!$this->dispatcher->hasListeners($event)) { $io->getErrorStyle()->warning(sprintf('The event "%s" does not have any registered listeners.', $event)); - return; + return 0; } $options = ['event' => $event]; @@ -89,5 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $options['raw_text'] = $input->getOption('raw'); $options['output'] = $io; $helper->describe($io, $this->dispatcher, $options); + + return 0; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php index bad3fa0598a5..9724e5122e2c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php @@ -73,7 +73,7 @@ protected function configure() * * @throws InvalidArgumentException When route does not exist */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $name = $input->getArgument('name'); @@ -105,6 +105,8 @@ protected function execute(InputInterface $input, OutputInterface $output) 'output' => $io, ]); } + + return 0; } private function findRouteNameContaining(string $name, RouteCollection $routes): array diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php index 85c1e5290575..124274d47427 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php @@ -124,7 +124,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); @@ -246,7 +246,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $io->getErrorStyle()->warning($outputMessage); - return; + return 0; } // Load the fallback catalogues @@ -295,6 +295,8 @@ protected function execute(InputInterface $input, OutputInterface $output) } $io->table($headers, $rows); + + return 0; } private function formatState(int $state): string diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/WorkflowDumpCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/WorkflowDumpCommand.php index ff91dc781837..cec930da1c0d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/WorkflowDumpCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/WorkflowDumpCommand.php @@ -59,7 +59,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $container = $this->getApplication()->getKernel()->getContainer(); $serviceId = $input->getArgument('name'); @@ -97,5 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output) ], ]; $output->writeln($dumper->dump($workflow->getDefinition(), $marking, $options)); + + return 0; } } diff --git a/src/Symfony/Bundle/WebServerBundle/Command/ServerLogCommand.php b/src/Symfony/Bundle/WebServerBundle/Command/ServerLogCommand.php index e8d51108ccab..ff9e32f589b8 100644 --- a/src/Symfony/Bundle/WebServerBundle/Command/ServerLogCommand.php +++ b/src/Symfony/Bundle/WebServerBundle/Command/ServerLogCommand.php @@ -123,6 +123,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->displayLog($input, $output, $clientId, $record); } + + return 0; } private function getLogs($socket) diff --git a/src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php b/src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php index 86edd88af9e2..fb83cb28ed99 100644 --- a/src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php +++ b/src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php @@ -164,6 +164,6 @@ protected function execute(InputInterface $input, OutputInterface $output) return 1; } - return null; + return 0; } } diff --git a/src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php b/src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php index 21e808ec8a3a..31edcee42d5c 100644 --- a/src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php +++ b/src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php @@ -103,6 +103,6 @@ protected function execute(InputInterface $input, OutputInterface $output) } } - return null; + return 0; } } diff --git a/src/Symfony/Bundle/WebServerBundle/Command/ServerStopCommand.php b/src/Symfony/Bundle/WebServerBundle/Command/ServerStopCommand.php index 8d7eb0b2eab9..b64107f8c2c7 100644 --- a/src/Symfony/Bundle/WebServerBundle/Command/ServerStopCommand.php +++ b/src/Symfony/Bundle/WebServerBundle/Command/ServerStopCommand.php @@ -77,6 +77,6 @@ protected function execute(InputInterface $input, OutputInterface $output) return 1; } - return null; + return 0; } } diff --git a/src/Symfony/Component/Console/CHANGELOG.md b/src/Symfony/Component/Console/CHANGELOG.md index d1b8a324c602..7d0c234e46b2 100644 --- a/src/Symfony/Component/Console/CHANGELOG.md +++ b/src/Symfony/Component/Console/CHANGELOG.md @@ -10,6 +10,7 @@ CHANGELOG * `Application` implements `ResetInterface` * marked all dispatched event classes as `@final` * added support for displaying table horizontally + * deprecated returning `null` from `Command::execute()`, return `0` instead 4.3.0 ----- diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php index 6bb3692cf3d3..460b91794505 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php @@ -150,7 +150,7 @@ protected function configure() * execute() method, you set the code to execute by passing * a Closure to the setCode() method. * - * @return int|void void or 0 if everything went fine, or an exit code + * @return int 0 if everything went fine, or an exit code * * @throws LogicException When this abstract method is not implemented * @@ -253,6 +253,10 @@ public function run(InputInterface $input, OutputInterface $output) $statusCode = ($this->code)($input, $output); } else { $statusCode = $this->execute($input, $output); + + if (!\is_int($statusCode)) { + @trigger_error(sprintf('A non numeric or nullable $statusCode returned by Command::execute() is deprecated since Symfony 4.4, return an integer value instead.'), E_USER_DEPRECATED); + } } return is_numeric($statusCode) ? (int) $statusCode : 0; diff --git a/src/Symfony/Component/Console/Command/HelpCommand.php b/src/Symfony/Component/Console/Command/HelpCommand.php index 23847766b6fd..b32be4c95cce 100644 --- a/src/Symfony/Component/Console/Command/HelpCommand.php +++ b/src/Symfony/Component/Console/Command/HelpCommand.php @@ -77,5 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output) ]); $this->command = null; + + return 0; } } diff --git a/src/Symfony/Component/Console/Command/ListCommand.php b/src/Symfony/Component/Console/Command/ListCommand.php index 15c8a1218d0d..8af952652872 100644 --- a/src/Symfony/Component/Console/Command/ListCommand.php +++ b/src/Symfony/Component/Console/Command/ListCommand.php @@ -74,6 +74,8 @@ protected function execute(InputInterface $input, OutputInterface $output) 'raw_text' => $input->getOption('raw'), 'namespace' => $input->getArgument('namespace'), ]); + + return 0; } private function createDefinition(): InputDefinition diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index dd30a9574137..f778e4f57449 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -1837,9 +1837,11 @@ public function __construct() class LazyCommand extends Command { - public function execute(InputInterface $input, OutputInterface $output) + public function execute(InputInterface $input, OutputInterface $output): int { $output->writeln('lazy-command called'); + + return 0; } } diff --git a/src/Symfony/Component/Console/Tests/Command/CommandTest.php b/src/Symfony/Component/Console/Tests/Command/CommandTest.php index 0c84d4175b44..c51a47c6853d 100644 --- a/src/Symfony/Component/Console/Tests/Command/CommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/CommandTest.php @@ -300,20 +300,6 @@ public function testRunWithInvalidOption() $tester->execute(['--bar' => true]); } - public function testRunReturnsIntegerExitCode() - { - $command = new \TestCommand(); - $exitCode = $command->run(new StringInput(''), new NullOutput()); - $this->assertSame(0, $exitCode, '->run() returns integer exit code (treats null as 0)'); - - $command = $this->getMockBuilder('TestCommand')->setMethods(['execute'])->getMock(); - $command->expects($this->once()) - ->method('execute') - ->willReturn('2.3'); - $exitCode = $command->run(new StringInput(''), new NullOutput()); - $this->assertSame(2, $exitCode, '->run() returns integer exit code (casts numeric to int)'); - } - public function testRunWithApplication() { $command = new \TestCommand(); diff --git a/src/Symfony/Component/Console/Tests/Fixtures/BarHiddenCommand.php b/src/Symfony/Component/Console/Tests/Fixtures/BarHiddenCommand.php index d500f8731f7d..58af8d816c38 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/BarHiddenCommand.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/BarHiddenCommand.php @@ -15,7 +15,8 @@ protected function configure() ; } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { + return 0; } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Foo1Command.php b/src/Symfony/Component/Console/Tests/Fixtures/Foo1Command.php index 6069576d1540..c4fc0e811227 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Foo1Command.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Foo1Command.php @@ -18,9 +18,11 @@ protected function configure() ; } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $this->input = $input; $this->output = $output; + + return 0; } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Foo2Command.php b/src/Symfony/Component/Console/Tests/Fixtures/Foo2Command.php index 0d9884013ebd..b3b6e6c06c93 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Foo2Command.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Foo2Command.php @@ -15,7 +15,8 @@ protected function configure() ; } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { + return 0; } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/Foo3Command.php b/src/Symfony/Component/Console/Tests/Fixtures/Foo3Command.php index adb3a2d809f7..d6ca5cd15c59 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/Foo3Command.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/Foo3Command.php @@ -14,7 +14,7 @@ protected function configure() ; } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { try { try { @@ -25,5 +25,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } catch (\Exception $e) { throw new \Exception('Third exception comment', 404, $e); } + + return 0; } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/FooCommand.php b/src/Symfony/Component/Console/Tests/Fixtures/FooCommand.php index 314460044789..fac25f21ec31 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/FooCommand.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/FooCommand.php @@ -23,11 +23,13 @@ protected function interact(InputInterface $input, OutputInterface $output) $output->writeln('interact called'); } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $this->input = $input; $this->output = $output; $output->writeln('called'); + + return 0; } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/FooHiddenCommand.php b/src/Symfony/Component/Console/Tests/Fixtures/FooHiddenCommand.php index 75fbf7804ddc..68e495b7610f 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/FooHiddenCommand.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/FooHiddenCommand.php @@ -15,7 +15,8 @@ protected function configure() ; } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { + return 0; } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/FooOptCommand.php b/src/Symfony/Component/Console/Tests/Fixtures/FooOptCommand.php index c9054671f94c..dea6d4d162fb 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/FooOptCommand.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/FooOptCommand.php @@ -25,12 +25,14 @@ protected function interact(InputInterface $input, OutputInterface $output) $output->writeln('interact called'); } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $this->input = $input; $this->output = $output; $output->writeln('called'); $output->writeln($this->input->getOption('fooopt')); + + return 0; } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/FooSubnamespaced1Command.php b/src/Symfony/Component/Console/Tests/Fixtures/FooSubnamespaced1Command.php index 95a4e6152484..c9fad78e152f 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/FooSubnamespaced1Command.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/FooSubnamespaced1Command.php @@ -18,9 +18,11 @@ protected function configure() ; } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $this->input = $input; $this->output = $output; + + return 0; } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/FooSubnamespaced2Command.php b/src/Symfony/Component/Console/Tests/Fixtures/FooSubnamespaced2Command.php index 08c5ff725fe0..dea20a49c508 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/FooSubnamespaced2Command.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/FooSubnamespaced2Command.php @@ -18,9 +18,11 @@ protected function configure() ; } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $this->input = $input; $this->output = $output; + + return 0; } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/FooWithoutAliasCommand.php b/src/Symfony/Component/Console/Tests/Fixtures/FooWithoutAliasCommand.php index e301cc5f5b3a..3d125500c4ed 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/FooWithoutAliasCommand.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/FooWithoutAliasCommand.php @@ -14,8 +14,10 @@ protected function configure() ; } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $output->writeln('called'); + + return 0; } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/FoobarCommand.php b/src/Symfony/Component/Console/Tests/Fixtures/FoobarCommand.php index 968162804cee..ab3c9ff0c9db 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/FoobarCommand.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/FoobarCommand.php @@ -17,9 +17,11 @@ protected function configure() ; } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $this->input = $input; $this->output = $output; + + return 0; } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/TestAmbiguousCommandRegistering.php b/src/Symfony/Component/Console/Tests/Fixtures/TestAmbiguousCommandRegistering.php index bece09fcdde8..71badf342814 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/TestAmbiguousCommandRegistering.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/TestAmbiguousCommandRegistering.php @@ -15,8 +15,10 @@ protected function configure() ; } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $output->write('test-ambiguous'); + + return 0; } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/TestAmbiguousCommandRegistering2.php b/src/Symfony/Component/Console/Tests/Fixtures/TestAmbiguousCommandRegistering2.php index 9dde48624546..127ea56a95f4 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/TestAmbiguousCommandRegistering2.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/TestAmbiguousCommandRegistering2.php @@ -14,8 +14,10 @@ protected function configure() ; } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $output->write('test-ambiguous2'); + + return 0; } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/TestCommand.php b/src/Symfony/Component/Console/Tests/Fixtures/TestCommand.php index eb7ccb33f6ca..4fb0410b7294 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/TestCommand.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/TestCommand.php @@ -19,6 +19,8 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('execute called'); + + return 0; } protected function interact(InputInterface $input, OutputInterface $output) diff --git a/src/Symfony/Component/ErrorRenderer/Command/DebugCommand.php b/src/Symfony/Component/ErrorRenderer/Command/DebugCommand.php index eac8f557e3b4..58cb57b68cbf 100644 --- a/src/Symfony/Component/ErrorRenderer/Command/DebugCommand.php +++ b/src/Symfony/Component/ErrorRenderer/Command/DebugCommand.php @@ -95,6 +95,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $io->newLine(); $io->table(['Format', 'Class'], $tableRows); } + + return 0; } private function formatClassLink(string $class): string diff --git a/src/Symfony/Component/Form/Command/DebugCommand.php b/src/Symfony/Component/Form/Command/DebugCommand.php index 341329b70b09..a6bf74ac9c83 100644 --- a/src/Symfony/Component/Form/Command/DebugCommand.php +++ b/src/Symfony/Component/Form/Command/DebugCommand.php @@ -152,6 +152,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $options['format'] = $input->getOption('format'); $options['show_deprecated'] = $input->getOption('show-deprecated'); $helper->describe($io, $object, $options); + + return 0; } private function getFqcnTypeClass(InputInterface $input, SymfonyStyle $io, string $shortClassName) diff --git a/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php b/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php index 07534f2d4bc3..4e9970387024 100644 --- a/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php +++ b/src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php @@ -227,6 +227,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $worker->run([ 'sleep' => $input->getOption('sleep') * 1000000, ]); + + return 0; } private function convertToBytes(string $memoryLimit): int diff --git a/src/Symfony/Component/Messenger/Command/DebugCommand.php b/src/Symfony/Component/Messenger/Command/DebugCommand.php index 1cb6771bc3b8..2c8c546c2350 100644 --- a/src/Symfony/Component/Messenger/Command/DebugCommand.php +++ b/src/Symfony/Component/Messenger/Command/DebugCommand.php @@ -96,6 +96,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $io->warning(sprintf('No handled message found in bus "%s".', $bus)); } } + + return 0; } private function formatConditions(array $options): string diff --git a/src/Symfony/Component/Messenger/Command/FailedMessagesRemoveCommand.php b/src/Symfony/Component/Messenger/Command/FailedMessagesRemoveCommand.php index a15791476cb5..52a93f5519b6 100644 --- a/src/Symfony/Component/Messenger/Command/FailedMessagesRemoveCommand.php +++ b/src/Symfony/Component/Messenger/Command/FailedMessagesRemoveCommand.php @@ -61,6 +61,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $shouldForce = $input->getOption('force'); $this->removeSingleMessage($input->getArgument('id'), $receiver, $io, $shouldForce); + + return 0; } private function removeSingleMessage(string $id, ReceiverInterface $receiver, SymfonyStyle $io, bool $shouldForce) diff --git a/src/Symfony/Component/Messenger/Command/FailedMessagesRetryCommand.php b/src/Symfony/Component/Messenger/Command/FailedMessagesRetryCommand.php index a3957ed54198..c8981b59adc8 100644 --- a/src/Symfony/Component/Messenger/Command/FailedMessagesRetryCommand.php +++ b/src/Symfony/Component/Messenger/Command/FailedMessagesRetryCommand.php @@ -110,11 +110,13 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->runInteractive($io, $shouldForce); - return; + return 0; } $this->retrySpecificIds($ids, $io, $shouldForce); $io->success('All done!'); + + return 0; } private function runInteractive(SymfonyStyle $io, bool $shouldForce) diff --git a/src/Symfony/Component/Messenger/Command/FailedMessagesShowCommand.php b/src/Symfony/Component/Messenger/Command/FailedMessagesShowCommand.php index 47491e8a2a24..d5ffc8d16418 100644 --- a/src/Symfony/Component/Messenger/Command/FailedMessagesShowCommand.php +++ b/src/Symfony/Component/Messenger/Command/FailedMessagesShowCommand.php @@ -71,6 +71,8 @@ protected function execute(InputInterface $input, OutputInterface $output) } else { $this->showMessage($id, $io); } + + return 0; } private function listMessages(SymfonyStyle $io, int $max) diff --git a/src/Symfony/Component/Messenger/Command/SetupTransportsCommand.php b/src/Symfony/Component/Messenger/Command/SetupTransportsCommand.php index 1adac92a2541..6f60a2c43438 100644 --- a/src/Symfony/Component/Messenger/Command/SetupTransportsCommand.php +++ b/src/Symfony/Component/Messenger/Command/SetupTransportsCommand.php @@ -76,5 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $io->note(sprintf('The "%s" transport does not support setup.', $transportName)); } } + + return 0; } } diff --git a/src/Symfony/Component/Messenger/Command/StopWorkersCommand.php b/src/Symfony/Component/Messenger/Command/StopWorkersCommand.php index 1e262763ead4..293b9f2422a0 100644 --- a/src/Symfony/Component/Messenger/Command/StopWorkersCommand.php +++ b/src/Symfony/Component/Messenger/Command/StopWorkersCommand.php @@ -68,5 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->restartSignalCachePool->save($cacheItem); $io->success('Signal successfully sent to stop any running workers.'); + + return 0; } } diff --git a/src/Symfony/Component/VarDumper/Command/ServerDumpCommand.php b/src/Symfony/Component/VarDumper/Command/ServerDumpCommand.php index eb807e35e8b4..c8a61da98c5b 100644 --- a/src/Symfony/Component/VarDumper/Command/ServerDumpCommand.php +++ b/src/Symfony/Component/VarDumper/Command/ServerDumpCommand.php @@ -75,7 +75,7 @@ protected function configure() ; } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $format = $input->getOption('format');