Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always return an int for Symfony Command execute method #40793

Merged
merged 2 commits into from
May 17, 2023

Conversation

phil-davis
Copy link
Contributor

Description

Symfony 5 requires that the Symfony Command execute method always returns an int

It is "sort of" optional for Symfony 4, but actually we should always return an int

This PR:

  • declares the return type to be int
  • adjusts places where something else has been returned, so that anint is now returned. That will fix potential problems with some commands.

How Has This Been Tested?

CI

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Database schema changes (next release will require increase of minor version instead of patch)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:
  • Changelog item, see TEMPLATE

@phil-davis phil-davis self-assigned this May 17, 2023
@@ -82,7 +82,6 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$groupPrincipalBackend = new GroupPrincipalBackend(
$this->groupManager
);
$config = \OC::$server->getConfig();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$config was unused.

@@ -134,6 +134,7 @@ public function execute(InputInterface $input, OutputInterface $output) {
}
}
$cursor->closeCursor();
return 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The execute method did not have an explicit return 0 (but in Symfony 4 that works - it breaks in Symfony 5)

@@ -70,5 +70,6 @@ protected function execute(InputInterface $input, OutputInterface $output) {
]);
});
$t->render();
return 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another place to explicitly return 0 at the end of the method.

@@ -252,11 +252,12 @@ protected function execute(InputInterface $input, OutputInterface $output) {
'@phan-var \Symfony\Component\Console\Helper\QuestionHelper $dialog';
$continue = $dialog->ask($input, $output, new Question('<question>Continue with the conversion (y/n)? [n] </question>', false));
if ($continue !== 'y') {
return;
return 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user has interactively answered "no". We are doing what the user said, so return 0 (which is success - we successfully did what the user said)

}
}
$intersectingTables = \array_intersect($toTables, $fromTables);
$this->convertDB($fromDB, $toDB, $intersectingTables, $input, $output);
return 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return 0 (success) at the end of execute

@@ -82,20 +82,20 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$output->writeln('This command requires the --path, --privateKey and --certificate.');
$output->writeln('Example: ./occ integrity:sign-app --path="/Users/lukasreschke/Programming/myapp/" --privateKey="/Users/lukasreschke/private/myapp.key" --certificate="/Users/lukasreschke/public/mycert.crt"');
$output->writeln('For more information please consult the documentation: '. $documentationUrl);
return null;
return 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null is not a proper return value. There is a problem, so return 1

$privateKeyPath = $input->getOption('privateKey');
$keyBundlePath = $input->getOption('certificate');
$path = $input->getOption('path');
if ($privateKeyPath === null || $keyBundlePath === null || $path === null) {
$output->writeln('--privateKey, --certificate and --path are required.');
return null;
return 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null is not a proper return value. There is a problem, so return 1

@owncloud owncloud deleted a comment from update-docs bot May 17, 2023
@sonarcloud
Copy link

sonarcloud bot commented May 17, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 5 Code Smells

68.6% 68.6% Coverage
11.8% 11.8% Duplication

@phil-davis phil-davis merged commit de8c711 into master May 17, 2023
3 checks passed
@delete-merged-branch delete-merged-branch bot deleted the symfony-command-execute branch May 17, 2023 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants