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 from Symfony Command execute method #787

Merged
merged 1 commit into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/Command/CheckUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,26 @@ protected function configure() {
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int|void|null
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output) {
protected function execute(InputInterface $input, OutputInterface $output): int {
try {
$uid = $input->getArgument('ocName');
$this->isAllowed($input->getOption('force'));
$this->confirmUserIsMapped($uid);
$exists = $this->backend->userExists($uid);
if ($exists === true) {
$output->writeln('The user is still available on LDAP.');
return;
return 0;
}

$output->writeln('The user does not exists on LDAP anymore.');
$output->writeln('The user does not exist on LDAP anymore.');
$output->writeln('Clean up the user\'s remnants by: ./occ user:delete "'
. $uid . '"');
} catch (\Exception $e) {
$output->writeln('<error>' . $e->getMessage(). '</error>');
}
return 0;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Command/CreateEmptyConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ protected function configure() {
/**
* Executes the current command.
*
* @return null|int null or 0 if everything went fine, or an error code
* @return int 0 if everything went fine, or an error code
*/
protected function execute(InputInterface $input, OutputInterface $output) {
protected function execute(InputInterface $input, OutputInterface $output): int {
$configID = $input->getArgument('configID');
if ($configID === null) {
$configPrefix = $this->helper->nextPossibleConfigurationPrefix();
Expand Down
6 changes: 4 additions & 2 deletions lib/Command/DeleteConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ protected function configure() {
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int|void|null
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output) {
protected function execute(InputInterface $input, OutputInterface $output): int {
$configPrefix = $input->getArgument('configID');

$success = $this->helper->deleteServerConfiguration($configPrefix);
Expand All @@ -68,6 +68,8 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$output->writeln("Deleted configuration with configID '{$configPrefix}'");
} else {
$output->writeln("Cannot delete configuration with configID '{$configPrefix}'");
return 1;
}
return 0;
}
}
2 changes: 1 addition & 1 deletion lib/Command/InvalidateCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function configure() {
->setDescription('invalidates the LDAP cache');
}

protected function execute(InputInterface $input, OutputInterface $output) {
protected function execute(InputInterface $input, OutputInterface $output): int {
$uProxyBackendsCount = $this->uProxy->getBackendCount() + 1; // +1 for the proxy itself
$gProxyBackendsCount = $this->gProxy->getBackendCount() + 1; // +1 for the proxy itself

Expand Down
5 changes: 3 additions & 2 deletions lib/Command/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ protected function validateOffsetAndLimit($offset, $limit) {
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int|void|null
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output) {
protected function execute(InputInterface $input, OutputInterface $output): int {
$helper = new Helper();
$configPrefixes = $helper->getServerConfigurationPrefixes(true);
$ldapWrapper = new LDAP();
Expand Down Expand Up @@ -134,5 +134,6 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$line = $name . ($printID ? ' ('.$id.')' : '');
$output->writeln($line);
}
return 0;
}
}
7 changes: 4 additions & 3 deletions lib/Command/SetConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,23 @@ protected function configure() {
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int|void|null
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output) {
protected function execute(InputInterface $input, OutputInterface $output): int {
$helper = new Helper();
$availableConfigs = $helper->getServerConfigurationPrefixes();
$configID = $input->getArgument('configID');
if (!\in_array($configID, $availableConfigs)) {
$output->writeln("Invalid configID");
return;
return 1;
}

$this->setValue(
$configID,
$input->getArgument('configKey'),
$input->getArgument('configValue')
);
return 0;
}

/**
Expand Down
7 changes: 4 additions & 3 deletions lib/Command/ShowConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,22 @@ protected function configure() {
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int|void|null
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output) {
protected function execute(InputInterface $input, OutputInterface $output): int {
$availableConfigs = $this->helper->getServerConfigurationPrefixes();
$configID = $input->getArgument('configID');
if ($configID !== null) {
$configIDs[] = $configID;
if (!\in_array($configIDs[0], $availableConfigs)) {
$output->writeln("Invalid configID");
return;
return 1;
}
} else {
$configIDs = $availableConfigs;
}
$this->renderConfigs($configIDs, $input, $output, $input->getOption('show-password'));
return 0;
}

/**
Expand Down
7 changes: 4 additions & 3 deletions lib/Command/TestConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ protected function configure() {
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int|void|null
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output) {
protected function execute(InputInterface $input, OutputInterface $output): int {
$availableConfigs = $this->helper->getServerConfigurationPrefixes();
$configId = $input->getArgument('configID');
if (!\in_array($configId, $availableConfigs, true)) {
$output->writeln("Invalid configID");
return;
return 1;
}

$result = $this->testConfig($configId);
Expand All @@ -92,6 +92,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
} else {
$output->writeln('Your LDAP server was kidnapped by aliens.');
}
return 0;
}

/**
Expand Down