Skip to content

Commit 38fc5d8

Browse files
jschaedlnicolas-grekas
authored andcommitted
[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
1 parent 9cd6abd commit 38fc5d8

13 files changed

+44
-18
lines changed

Command/AboutCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected function configure()
5454
/**
5555
* {@inheritdoc}
5656
*/
57-
protected function execute(InputInterface $input, OutputInterface $output)
57+
protected function execute(InputInterface $input, OutputInterface $output): int
5858
{
5959
$io = new SymfonyStyle($input, $output);
6060

@@ -100,6 +100,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
100100
}
101101

102102
$io->table([], $rows);
103+
104+
return 0;
103105
}
104106

105107
private static function formatPath(string $path, string $baseDir): string

Command/CacheClearCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected function configure()
7272
/**
7373
* {@inheritdoc}
7474
*/
75-
protected function execute(InputInterface $input, OutputInterface $output)
75+
protected function execute(InputInterface $input, OutputInterface $output): int
7676
{
7777
$fs = $this->filesystem;
7878
$io = new SymfonyStyle($input, $output);
@@ -175,6 +175,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
175175
}
176176

177177
$io->success(sprintf('Cache for the "%s" environment (debug=%s) was successfully cleared.', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
178+
179+
return 0;
178180
}
179181

180182
private function warmup(string $warmupDir, string $realCacheDir, bool $enableOptionalWarmers = true)

Command/CachePoolClearCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected function configure()
6060
/**
6161
* {@inheritdoc}
6262
*/
63-
protected function execute(InputInterface $input, OutputInterface $output)
63+
protected function execute(InputInterface $input, OutputInterface $output): int
6464
{
6565
$io = new SymfonyStyle($input, $output);
6666
$kernel = $this->getApplication()->getKernel();
@@ -99,5 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9999
}
100100

101101
$io->success('Cache was successfully cleared.');
102+
103+
return 0;
102104
}
103105
}

Command/CachePoolDeleteCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected function configure()
5959
/**
6060
* {@inheritdoc}
6161
*/
62-
protected function execute(InputInterface $input, OutputInterface $output)
62+
protected function execute(InputInterface $input, OutputInterface $output): int
6363
{
6464
$io = new SymfonyStyle($input, $output);
6565
$pool = $input->getArgument('pool');
@@ -69,13 +69,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
6969
if (!$cachePool->hasItem($key)) {
7070
$io->note(sprintf('Cache item "%s" does not exist in cache pool "%s".', $key, $pool));
7171

72-
return;
72+
return 0;
7373
}
7474

7575
if (!$cachePool->deleteItem($key)) {
7676
throw new \Exception(sprintf('Cache item "%s" could not be deleted.', $key));
7777
}
7878

7979
$io->success(sprintf('Cache item "%s" was successfully deleted.', $key));
80+
81+
return 0;
8082
}
8183
}

Command/CachePoolListCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ protected function configure()
5151
/**
5252
* {@inheritdoc}
5353
*/
54-
protected function execute(InputInterface $input, OutputInterface $output)
54+
protected function execute(InputInterface $input, OutputInterface $output): int
5555
{
5656
$io = new SymfonyStyle($input, $output);
5757

5858
$io->table(['Pool name'], array_map(function ($pool) {
5959
return [$pool];
6060
}, $this->poolNames));
61+
62+
return 0;
6163
}
6264
}

Command/CachePoolPruneCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected function configure()
5757
/**
5858
* {@inheritdoc}
5959
*/
60-
protected function execute(InputInterface $input, OutputInterface $output)
60+
protected function execute(InputInterface $input, OutputInterface $output): int
6161
{
6262
$io = new SymfonyStyle($input, $output);
6363

@@ -67,5 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6767
}
6868

6969
$io->success('Successfully pruned cache pool(s).');
70+
71+
return 0;
7072
}
7173
}

Command/CacheWarmupCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected function configure()
6666
/**
6767
* {@inheritdoc}
6868
*/
69-
protected function execute(InputInterface $input, OutputInterface $output)
69+
protected function execute(InputInterface $input, OutputInterface $output): int
7070
{
7171
$io = new SymfonyStyle($input, $output);
7272

@@ -80,5 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8080
$this->cacheWarmer->warmUp($kernel->getContainer()->getParameter('kernel.cache_dir'));
8181

8282
$io->success(sprintf('Cache for the "%s" environment (debug=%s) was successfully warmed.', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
83+
84+
return 0;
8385
}
8486
}

Command/ConfigDebugCommand.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected function configure()
6363
/**
6464
* {@inheritdoc}
6565
*/
66-
protected function execute(InputInterface $input, OutputInterface $output)
66+
protected function execute(InputInterface $input, OutputInterface $output): int
6767
{
6868
$io = new SymfonyStyle($input, $output);
6969
$errorIo = $io->getErrorStyle();
@@ -73,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7373
$errorIo->comment('Provide the name of a bundle as the first argument of this command to dump its configuration. (e.g. <comment>debug:config FrameworkBundle</comment>)');
7474
$errorIo->comment('For dumping a specific option, add its path as the second argument of this command. (e.g. <comment>debug:config FrameworkBundle serializer</comment> to dump the <comment>framework.serializer</comment> configuration)');
7575

76-
return;
76+
return 0;
7777
}
7878

7979
$extension = $this->findExtension($name);
@@ -101,7 +101,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
101101

102102
$io->writeln(Yaml::dump([$extensionAlias => $config], 10));
103103

104-
return;
104+
return 0;
105105
}
106106

107107
try {
@@ -115,6 +115,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
115115
$io->title(sprintf('Current configuration for "%s.%s"', $extensionAlias, $path));
116116

117117
$io->writeln(Yaml::dump($config, 10));
118+
119+
return 0;
118120
}
119121

120122
private function compileContainer(): ContainerBuilder

Command/ContainerDebugCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ protected function configure()
114114
/**
115115
* {@inheritdoc}
116116
*/
117-
protected function execute(InputInterface $input, OutputInterface $output)
117+
protected function execute(InputInterface $input, OutputInterface $output): int
118118
{
119119
if ($input->getOption('show-private')) {
120120
@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)
184184
$errorIo->comment('To search for a specific service, re-run this command with a search term. (e.g. <comment>debug:container log</comment>)');
185185
}
186186
}
187+
188+
return 0;
187189
}
188190

189191
/**

Command/EventDispatcherDebugCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected function configure()
6969
*
7070
* @throws \LogicException
7171
*/
72-
protected function execute(InputInterface $input, OutputInterface $output)
72+
protected function execute(InputInterface $input, OutputInterface $output): int
7373
{
7474
$io = new SymfonyStyle($input, $output);
7575

@@ -78,7 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7878
if (!$this->dispatcher->hasListeners($event)) {
7979
$io->getErrorStyle()->warning(sprintf('The event "%s" does not have any registered listeners.', $event));
8080

81-
return;
81+
return 0;
8282
}
8383

8484
$options = ['event' => $event];
@@ -89,5 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8989
$options['raw_text'] = $input->getOption('raw');
9090
$options['output'] = $io;
9191
$helper->describe($io, $this->dispatcher, $options);
92+
93+
return 0;
9294
}
9395
}

0 commit comments

Comments
 (0)