From a0e70a9cef2c82d58b17adc9fffbc80d18457e98 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sat, 10 Aug 2024 11:13:01 -0700 Subject: [PATCH 1/2] execute() - Add `return 0` for more commands --- src/Command/CliCommand.php | 3 ++- src/Command/CoreInstallCommand.php | 2 +- src/Command/CoreUninstallCommand.php | 4 +++- src/Command/FillCommand.php | 3 ++- src/Command/HttpCommand.php | 3 ++- src/Command/UpgradeDlCommand.php | 3 ++- src/Command/UpgradeReportCommand.php | 3 ++- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Command/CliCommand.php b/src/Command/CliCommand.php index 872e99a6..9dca5f27 100644 --- a/src/Command/CliCommand.php +++ b/src/Command/CliCommand.php @@ -21,7 +21,7 @@ protected function configure() { $this->configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $this->boot($input, $output); $cv = new Application(); @@ -32,6 +32,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { // new ApiMatcher(), //)); $sh->run(); + return 0; } } diff --git a/src/Command/CoreInstallCommand.php b/src/Command/CoreInstallCommand.php index c8fcb0f6..76166030 100644 --- a/src/Command/CoreInstallCommand.php +++ b/src/Command/CoreInstallCommand.php @@ -52,7 +52,7 @@ protected function configure() { $this->configureBootOptions('none'); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $setup = $this->bootSetupSubsystem($input, $output); $debugMode = FALSE; diff --git a/src/Command/CoreUninstallCommand.php b/src/Command/CoreUninstallCommand.php index fe499040..d6563fca 100644 --- a/src/Command/CoreUninstallCommand.php +++ b/src/Command/CoreUninstallCommand.php @@ -31,7 +31,7 @@ protected function configure() { $this->configureBootOptions('none'); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $setup = $this->bootSetupSubsystem($input, $output); $debugEvent = $this->parseOptionalOption($input, ['--debug-event'], NULL, ''); @@ -74,6 +74,8 @@ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln(sprintf("Removing %s from %s", basename($setup->getModel()->settingsPath), dirname($setup->getModel()->settingsPath))); $setup->uninstallFiles(); } + + return 0; } } diff --git a/src/Command/FillCommand.php b/src/Command/FillCommand.php index 9d4d0d5a..fb332d27 100644 --- a/src/Command/FillCommand.php +++ b/src/Command/FillCommand.php @@ -58,7 +58,7 @@ public function __construct($name = NULL) { ); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $this->boot($input, $output); if (!$input->getOption('file')) { $reader = new SiteConfigReader(CIVICRM_SETTINGS_PATH); @@ -105,6 +105,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { }); $output->writeln(sprintf("Please edit %s", Config::getFileName())); } + return 0; } } diff --git a/src/Command/HttpCommand.php b/src/Command/HttpCommand.php index d8c43c44..c79b78ce 100644 --- a/src/Command/HttpCommand.php +++ b/src/Command/HttpCommand.php @@ -46,7 +46,7 @@ protected function configure() { $this->configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $this->boot($input, $output); $method = $input->getOption('request'); @@ -67,6 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $statusCode = $this->sendRequest($output, $method, $row['value'], array_merge($headers, $row['headers'] ?? []), $data); return ($statusCode >= 200 && $statusCode < 300) ? 0 : $statusCode; } + return 0; } /** diff --git a/src/Command/UpgradeDlCommand.php b/src/Command/UpgradeDlCommand.php index a9931ee1..7b1c7e62 100644 --- a/src/Command/UpgradeDlCommand.php +++ b/src/Command/UpgradeDlCommand.php @@ -37,7 +37,7 @@ protected function configure() { // parent::configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { // Figure out the URL, whether specified or automatic $url = $input->getOption('url'); if (empty($url)) { @@ -114,6 +114,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $result['installedTo'] = $dest; $this->sendResult($input, $output, $result); + return 0; } /** diff --git a/src/Command/UpgradeReportCommand.php b/src/Command/UpgradeReportCommand.php index 25d47769..eaf9b367 100644 --- a/src/Command/UpgradeReportCommand.php +++ b/src/Command/UpgradeReportCommand.php @@ -55,7 +55,7 @@ protected function configure() { // parent::configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { // $report will be POSTed too https://upgrade.civicrm.org/report. // See also: https://github.com/civicrm/civicrm-dist-manager#route-post-report-web-service @@ -111,6 +111,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $report['response'] = $this->reportToCivi($report); $this->sendResult($input, $output, $report); + return 0; } /** From cd90760d5d965b25cb7e02a366d768ebbffd6671 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sat, 10 Aug 2024 11:37:27 -0700 Subject: [PATCH 2/2] execute() - Declare explicit return type This is strictly necessary for Symfony 5. However, the actual beahvior in S5 is the throw an error if you don't return `int`. So we might as well get the IDE to give hints about this. --- src/Command/AngularHtmlListCommand.php | 2 +- src/Command/AngularHtmlShowCommand.php | 2 +- src/Command/AngularModuleListCommand.php | 2 +- src/Command/Api4Command.php | 2 +- src/Command/ApiCommand.php | 2 +- src/Command/CoreCheckReqCommand.php | 2 +- src/Command/EditCommand.php | 2 +- src/Command/EvalCommand.php | 2 +- src/Command/ExtensionDisableCommand.php | 2 +- src/Command/ExtensionDownloadCommand.php | 2 +- src/Command/ExtensionEnableCommand.php | 2 +- src/Command/ExtensionListCommand.php | 2 +- src/Command/ExtensionUninstallCommand.php | 2 +- src/Command/FlushCommand.php | 2 +- src/Command/PathCommand.php | 2 +- src/Command/PipeCommand.php | 2 +- src/Command/ScriptCommand.php | 2 +- src/Command/SettingGetCommand.php | 2 +- src/Command/SettingRevertCommand.php | 2 +- src/Command/SettingSetCommand.php | 2 +- src/Command/SqlCliCommand.php | 2 +- src/Command/UpgradeCommand.php | 2 +- src/Command/UpgradeGetCommand.php | 2 +- src/Command/UrlCommand.php | 2 +- 24 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Command/AngularHtmlListCommand.php b/src/Command/AngularHtmlListCommand.php index 907488ce..7a0c4af7 100644 --- a/src/Command/AngularHtmlListCommand.php +++ b/src/Command/AngularHtmlListCommand.php @@ -37,7 +37,7 @@ protected function configure() { $this->configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $this->boot($input, $output); if (!$input->getOption('user')) { $output->getErrorOutput()->writeln("For a full list, try passing --user=[username]."); diff --git a/src/Command/AngularHtmlShowCommand.php b/src/Command/AngularHtmlShowCommand.php index 055810dd..41801d2c 100644 --- a/src/Command/AngularHtmlShowCommand.php +++ b/src/Command/AngularHtmlShowCommand.php @@ -41,7 +41,7 @@ protected function configure() { $this->configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $this->boot($input, $output); if (!$input->getOption('user')) { $output->getErrorOutput()->writeln("For a full list, try passing --user=[username]."); diff --git a/src/Command/AngularModuleListCommand.php b/src/Command/AngularModuleListCommand.php index 8f5c62cb..c54766a2 100644 --- a/src/Command/AngularModuleListCommand.php +++ b/src/Command/AngularModuleListCommand.php @@ -39,7 +39,7 @@ protected function configure() { $this->configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $this->boot($input, $output); if (!$input->getOption('user')) { $output->getErrorOutput()->writeln("For a full list, try passing --user=[username]."); diff --git a/src/Command/Api4Command.php b/src/Command/Api4Command.php index 6834e4bd..9c12af3c 100644 --- a/src/Command/Api4Command.php +++ b/src/Command/Api4Command.php @@ -125,7 +125,7 @@ protected function configure() { $this->configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $C = ''; $_C = ''; $I = ''; diff --git a/src/Command/ApiCommand.php b/src/Command/ApiCommand.php index 8341ae87..0c1f1eb0 100644 --- a/src/Command/ApiCommand.php +++ b/src/Command/ApiCommand.php @@ -50,7 +50,7 @@ protected function configure() { $this->configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $C = ''; $_C = ''; $I = ''; diff --git a/src/Command/CoreCheckReqCommand.php b/src/Command/CoreCheckReqCommand.php index f82c122c..c6af514f 100644 --- a/src/Command/CoreCheckReqCommand.php +++ b/src/Command/CoreCheckReqCommand.php @@ -38,7 +38,7 @@ protected function configure() { $this->configureBootOptions('none'); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $filterSeverities = $this->parseFilter($input); $showBootMsgsByDefault = in_array($input->getOption('out'), ['table', 'pretty']); diff --git a/src/Command/EditCommand.php b/src/Command/EditCommand.php index 751ca27f..6e5f3549 100644 --- a/src/Command/EditCommand.php +++ b/src/Command/EditCommand.php @@ -46,7 +46,7 @@ public function __construct($name = NULL) { }); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $this->boot($input, $output); $config = Config::read(); diff --git a/src/Command/EvalCommand.php b/src/Command/EvalCommand.php index 0c854ad3..69e9d0fb 100644 --- a/src/Command/EvalCommand.php +++ b/src/Command/EvalCommand.php @@ -40,7 +40,7 @@ protected function configure() { $this->configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $this->boot($input, $output); if ($input->getOption('out') === 'auto') { diff --git a/src/Command/ExtensionDisableCommand.php b/src/Command/ExtensionDisableCommand.php index d3b73f28..abc058a3 100644 --- a/src/Command/ExtensionDisableCommand.php +++ b/src/Command/ExtensionDisableCommand.php @@ -37,7 +37,7 @@ protected function configure() { $this->configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $this->boot($input, $output); list ($foundKeys, $missingKeys) = $this->parseKeys($input, $output); diff --git a/src/Command/ExtensionDownloadCommand.php b/src/Command/ExtensionDownloadCommand.php index 34852345..f5820af6 100644 --- a/src/Command/ExtensionDownloadCommand.php +++ b/src/Command/ExtensionDownloadCommand.php @@ -68,7 +68,7 @@ protected function initialize(InputInterface $input, OutputInterface $output) { parent::initialize($input, $output); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $fs = new Filesystem(); if ($extRepoUrl = $this->parseRepoUrl($input)) { diff --git a/src/Command/ExtensionEnableCommand.php b/src/Command/ExtensionEnableCommand.php index 10d79556..0de3bba5 100644 --- a/src/Command/ExtensionEnableCommand.php +++ b/src/Command/ExtensionEnableCommand.php @@ -40,7 +40,7 @@ protected function configure() { $this->configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $this->boot($input, $output); // Refresh extensions if (a) ---refresh enabled or (b) there's a cache-miss. diff --git a/src/Command/ExtensionListCommand.php b/src/Command/ExtensionListCommand.php index fe88c688..a2df1719 100644 --- a/src/Command/ExtensionListCommand.php +++ b/src/Command/ExtensionListCommand.php @@ -49,7 +49,7 @@ protected function configure() { $this->configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $wo = ($input->getOption('out') === 'table') ? (OutputInterface::OUTPUT_NORMAL | OutputInterface::VERBOSITY_NORMAL) : (OutputInterface::OUTPUT_NORMAL | OutputInterface::VERBOSITY_VERBOSE); diff --git a/src/Command/ExtensionUninstallCommand.php b/src/Command/ExtensionUninstallCommand.php index 691d2edf..839ab593 100644 --- a/src/Command/ExtensionUninstallCommand.php +++ b/src/Command/ExtensionUninstallCommand.php @@ -37,7 +37,7 @@ protected function configure() { $this->configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $this->boot($input, $output); list ($foundKeys, $missingKeys) = $this->parseKeys($input, $output); diff --git a/src/Command/FlushCommand.php b/src/Command/FlushCommand.php index fad03914..b522a90a 100644 --- a/src/Command/FlushCommand.php +++ b/src/Command/FlushCommand.php @@ -22,7 +22,7 @@ protected function configure() { $this->configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { // The main reason we have this as separate command -- so we can ignore // stale class-references that might be retained by the container cache. define('CIVICRM_CONTAINER_CACHE', 'never'); diff --git a/src/Command/PathCommand.php b/src/Command/PathCommand.php index bc84848e..20348d85 100644 --- a/src/Command/PathCommand.php +++ b/src/Command/PathCommand.php @@ -58,7 +58,7 @@ protected function configure() { $this->configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $this->boot($input, $output); if (!$input->getOption('ext') && !$input->getOption('config') && !$input->getOption('dynamic')) { diff --git a/src/Command/PipeCommand.php b/src/Command/PipeCommand.php index 8b5f258f..25d4140f 100644 --- a/src/Command/PipeCommand.php +++ b/src/Command/PipeCommand.php @@ -50,7 +50,7 @@ protected function configure() { $this->configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $this->boot($input, $output); if (!is_callable(['Civi', 'pipe'])) { fwrite(STDERR, "This version of CiviCRM does not include Civi::pipe() support.\n"); diff --git a/src/Command/ScriptCommand.php b/src/Command/ScriptCommand.php index 994f2283..08e58f01 100644 --- a/src/Command/ScriptCommand.php +++ b/src/Command/ScriptCommand.php @@ -21,7 +21,7 @@ protected function configure() { $this->configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $fs = new Filesystem(); $origScript = $fs->toAbsolutePath($input->getArgument('script')); $scriptArguments = $input->getArgument('scriptArguments'); diff --git a/src/Command/SettingGetCommand.php b/src/Command/SettingGetCommand.php index 34bb9f26..6bdd276e 100644 --- a/src/Command/SettingGetCommand.php +++ b/src/Command/SettingGetCommand.php @@ -71,7 +71,7 @@ protected function configure() { $this->configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $this->boot($input, $output); $filter = $this->createSettingFilter($input->getArgument('name')); diff --git a/src/Command/SettingRevertCommand.php b/src/Command/SettingRevertCommand.php index 7d3293c8..15420cdc 100644 --- a/src/Command/SettingRevertCommand.php +++ b/src/Command/SettingRevertCommand.php @@ -62,7 +62,7 @@ protected function configure() { $this->configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $this->boot($input, $output); $errorOutput = is_callable([$output, 'getErrorOutput']) ? $output->getErrorOutput() : $output; diff --git a/src/Command/SettingSetCommand.php b/src/Command/SettingSetCommand.php index f1e11ce1..5b915956 100644 --- a/src/Command/SettingSetCommand.php +++ b/src/Command/SettingSetCommand.php @@ -85,7 +85,7 @@ protected function configure() { $this->configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $C = ''; $_C = ''; $I = ''; diff --git a/src/Command/SqlCliCommand.php b/src/Command/SqlCliCommand.php index ea970567..2b353e05 100644 --- a/src/Command/SqlCliCommand.php +++ b/src/Command/SqlCliCommand.php @@ -47,7 +47,7 @@ protected function initialize(InputInterface $input, OutputInterface $output) { } } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $this->boot($input, $output); $datasource = new Datasource(); diff --git a/src/Command/UpgradeCommand.php b/src/Command/UpgradeCommand.php index 48853bdf..cbf3e877 100644 --- a/src/Command/UpgradeCommand.php +++ b/src/Command/UpgradeCommand.php @@ -24,7 +24,7 @@ protected function configure() { // parent::configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { throw new \RuntimeException("FIXME: Calls to run() should be escaped, e.g. with Process::sprintf()"); diff --git a/src/Command/UpgradeGetCommand.php b/src/Command/UpgradeGetCommand.php index 483e874e..56f358a3 100644 --- a/src/Command/UpgradeGetCommand.php +++ b/src/Command/UpgradeGetCommand.php @@ -42,7 +42,7 @@ protected function configure() { $this->configureBootOptions(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $result = array(); $exitCode = 0; $stability = $input->getOption('stability'); diff --git a/src/Command/UrlCommand.php b/src/Command/UrlCommand.php index 349dffbe..b712836a 100644 --- a/src/Command/UrlCommand.php +++ b/src/Command/UrlCommand.php @@ -76,7 +76,7 @@ protected function initialize(InputInterface $input, OutputInterface $output) { } } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { if (in_array($input->getOption('out'), Encoder::getTabularFormats()) && !in_array($input->getOption('out'), Encoder::getFormats())) { $input->setOption('tabular', TRUE);