Skip to content

Commit 603ad9e

Browse files
committed
[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 001777a commit 603ad9e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+126
-41
lines changed

src/Symfony/Bridge/Twig/Command/DebugCommand.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
111111

112112
switch ($input->getOption('format')) {
113113
case 'text':
114-
return $name ? $this->displayPathsText($io, $name) : $this->displayGeneralText($io, $filter);
114+
$name ? $this->displayPathsText($io, $name) : $this->displayGeneralText($io, $filter);
115+
break;
115116
case 'json':
116-
return $name ? $this->displayPathsJson($io, $name) : $this->displayGeneralJson($io, $filter);
117+
$name ? $this->displayPathsJson($io, $name) : $this->displayGeneralJson($io, $filter);
118+
break;
117119
default:
118120
throw new InvalidArgumentException(sprintf('The format "%s" is not supported.', $input->getOption('format')));
119121
}
122+
123+
return 0;
120124
}
121125

122126
private function displayPathsText(SymfonyStyle $io, string $name)

src/Symfony/Bundle/FrameworkBundle/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

src/Symfony/Bundle/FrameworkBundle/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)

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php

Lines changed: 6 additions & 4 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,20 +101,22 @@ 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 {
108108
$config = $this->getConfigForPath($config, $path, $extensionAlias);
109109
} catch (LogicException $e) {
110110
$errorIo->error($e->getMessage());
111111

112-
return;
112+
return 1;
113113
}
114114

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

src/Symfony/Bundle/FrameworkBundle/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
/**

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy