Skip to content

Commit

Permalink
Add return value to commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrej-kuhnel committed Jan 3, 2023
1 parent ecf4e6f commit f1ac75a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/Command/MangoCancelUnpaidOrdersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function configure(): void
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$expirationTime = $this->expirationPeriod;
$methodCodes = $this->expirationMethodCodes;
Expand All @@ -72,5 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output): void
$this->unpaidCartsStateUpdater->cancel();

$this->entityManager->flush();

return 0;
}
}
4 changes: 3 additions & 1 deletion src/Command/UpdateExchangeRatesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function configure(): void
->setDescription('Update exchange rates.');
}

protected function execute(InputInterface $input, OutputInterface $output): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title($this->getName() . ' started at ' . date('Y-m-d H:i:s'));
Expand Down Expand Up @@ -122,5 +122,7 @@ protected function execute(InputInterface $input, OutputInterface $output): void
$io->success(
$this->getName() . ' at ' . date('Y-m-d H:i:s')
);

return 0;
}
}
12 changes: 7 additions & 5 deletions src/Command/UpdateProductPriceByExchangeRatesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function configure(): void
->setDescription('Update product prices by exchange rates.');
}

protected function execute(InputInterface $input, OutputInterface $output): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title($this->getName() . ' started at ' . date('Y-m-d H:i:s'));
Expand All @@ -86,7 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output): void
if (!in_array($decimals, [0, 1, 2], true)) {
$io->error('Option round has allowed values 0, 1 or 2');

return;
return 1;
}

assert(is_string($sourceChannelParam));
Expand All @@ -100,7 +100,7 @@ protected function execute(InputInterface $input, OutputInterface $output): void
$this->logger->error($errorMsg);
$io->error($errorMsg);

return;
return 2;
}
assert($sourceChannel instanceof ChannelInterface);
assert($targetChannel instanceof ChannelInterface);
Expand All @@ -121,15 +121,15 @@ protected function execute(InputInterface $input, OutputInterface $output): void
$this->logger->error($errorMsg);
$io->error($errorMsg);

return;
return 3;
}
assert($exchangeRate instanceof ExchangeRateInterface);
if ($exchangeRate->getRatio() === null || $exchangeRate->getRatio() === 0) {
$errorMsg = 'Exchange Rate is 0.';
$this->logger->error($errorMsg);
$io->error($errorMsg);

return;
return 4;
}
}

Expand Down Expand Up @@ -175,6 +175,8 @@ protected function execute(InputInterface $input, OutputInterface $output): void
$io->success(
$this->getName() . ' at ' . date('Y-m-d H:i:s')
);

return 0;
}

private function roundPrice(int $price, int $decimals): int
Expand Down

0 comments on commit f1ac75a

Please sign in to comment.