Skip to content

Commit

Permalink
Fix return type of commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mitelg committed Mar 3, 2023
1 parent 4528f75 commit 85c1e05
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 79 deletions.
3 changes: 2 additions & 1 deletion src/Command/CacheCommand.php
Expand Up @@ -8,6 +8,7 @@

namespace ShopwareCli\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -30,6 +31,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->container->get('cache')->clear();

return 0;
return Command::SUCCESS;
}
}
5 changes: 3 additions & 2 deletions src/Command/CacheGetCommand.php
Expand Up @@ -8,6 +8,7 @@

namespace ShopwareCli\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -41,14 +42,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln($key);
}

return 0;
return Command::SUCCESS;
}

foreach ($keys as $key) {
$output->writeln("<question>{$key}</question>");
$output->writeln($this->container->get('cache')->read($key));
}

return 0;
return Command::SUCCESS;
}
}
11 changes: 6 additions & 5 deletions src/Extensions/Shopware/AutoUpdate/Command/RollbackCommand.php
Expand Up @@ -10,6 +10,7 @@

use Humbug\SelfUpdate\Updater;
use ShopwareCli\Command\BaseCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -29,32 +30,32 @@ public function __construct(Updater $updater)
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName('rollback');
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
try {
$result = $this->updater->rollback();
if (!$result) {
$output->writeln('Rollback failed!');

return 1;
return Command::FAILURE;
}
} catch (\Exception $e) {
$output->writeln($e->getMessage());
$output->writeln('Unable to rollback');

return 1;
return Command::FAILURE;
}

$output->writeln('Rollback successful');

return 0;
return Command::SUCCESS;
}
}
11 changes: 6 additions & 5 deletions src/Extensions/Shopware/AutoUpdate/Command/SelfUpdateCommand.php
Expand Up @@ -10,6 +10,7 @@

use Humbug\SelfUpdate\Updater;
use ShopwareCli\Command\BaseCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -29,22 +30,22 @@ public function __construct(Updater $updater)
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName('self-update');
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
try {
$result = $this->updater->update();
if (!$result) {
$output->writeln('No update needed.');

return 0;
return Command::SUCCESS;
}

$new = $this->updater->getNewVersion();
Expand All @@ -56,12 +57,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
$new
));

return 0;
return Command::SUCCESS;
} catch (\Exception $e) {
$output->writeln('Unable to update. Please check your connection');
$this->printException($output, $e);

return 1;
return Command::FAILURE;
}
}

Expand Down
Expand Up @@ -11,6 +11,7 @@
use Shopware\DataGenerator\DataGenerator;
use Shopware\DataGenerator\Struct\Config;
use ShopwareCli\Command\BaseCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -21,7 +22,7 @@ class CreateDataCommand extends BaseCommand

protected $zipDir;

public function interact(InputInterface $input, OutputInterface $output)
public function interact(InputInterface $input, OutputInterface $output): void
{
$articles = $input->getOption('articles');
$orders = $input->getOption('orders');
Expand Down Expand Up @@ -66,7 +67,7 @@ public function validateInt($input): int
return (int) $input;
}

protected function configure()
protected function configure(): void
{
$this
->setName('generate')
Expand Down Expand Up @@ -189,7 +190,7 @@ protected function configure()
');
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @var DataGenerator $generator */
$generator = $this->container->get('data_generator');
Expand All @@ -215,7 +216,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'<error>At least one of the optional arguments should be provided. Use the --help option for more info.</error>'
);

return;
return Command::FAILURE;
}

$shopwarePath = $input->getOption('installDir');
Expand All @@ -228,7 +229,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!\array_key_exists('db', $shopwareConfig)) {
$output->writeln('<error>Invalid Shopware configuration file.</error>');

return;
return Command::FAILURE;
}
$writerManager->setConfig('database', $shopwareConfig['db']);
$writerManager->setDefaultWriterType('database');
Expand Down Expand Up @@ -264,6 +265,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$generator->run();
}
}

return Command::SUCCESS;
}

protected function configureGenerator(
Expand Down Expand Up @@ -318,12 +321,7 @@ protected function configureGenerator(
$config->setMaxVariants($maxVariants);
}

/**
* @param string $optionName
* @param string|null $optionHumanName
* @param int $default
*/
private function askConfigOptions(InputInterface $input, $optionName, $optionHumanName = null, $default = 0): void
private function askConfigOptions(InputInterface $input, string $optionName, ?string $optionHumanName = null, int $default = 0): void
{
$ioService = $this->container->get('io_service');

Expand Down
Expand Up @@ -11,6 +11,7 @@
use ShopwareCli\Command\BaseCommand;
use ShopwareCli\Services\ProcessExecutor;
use ShopwareCli\Services\ShopwareInfo;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -51,7 +52,7 @@ protected function configure()
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$path = $this->checkPath($input);

Expand All @@ -65,6 +66,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
/** @var ProcessExecutor $processExecutor */
$processExecutor = $this->container->get('process_executor');
$processExecutor->execute($shopwareInfo->getCacheDir($path) . '/clear_cache.sh');

return Command::SUCCESS;
}

private function checkPath(InputInterface $input): string
Expand Down
Expand Up @@ -13,13 +13,14 @@
use ShopwareCli\Command\BaseCommand;
use ShopwareCli\Config;
use ShopwareCli\Services\IoService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class ShopwareInstallReleaseCommand extends BaseCommand
{
public function interact(InputInterface $input, OutputInterface $output)
public function interact(InputInterface $input, OutputInterface $output): void
{
$this->validateInput($input);

Expand Down Expand Up @@ -80,7 +81,7 @@ protected function getConfig(): Config
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this->setName('install:release')
->setDescription('Allows setting up shopware from release package.')
Expand All @@ -99,7 +100,7 @@ protected function configure()
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$request = new InstallationRequest([
'release' => $input->getOption('release'),
Expand Down Expand Up @@ -130,6 +131,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
/** @var Release $installService */
$installService = $this->container->get('shopware_release_install_service');
$installService->installShopware($request);

return Command::SUCCESS;
}

/**
Expand Down
Expand Up @@ -11,6 +11,7 @@
use Shopware\Install\Services\Install\Vcs;
use ShopwareCli\Command\BaseCommand;
use ShopwareCli\Services\IoService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -19,7 +20,7 @@ class ShopwareInstallVcsCommand extends BaseCommand
{
private const MAIN_BRANCH = '5.6';

public function interact(InputInterface $input, OutputInterface $output)
public function interact(InputInterface $input, OutputInterface $output): void
{
/** @var IoService $ioService */
$ioService = $this->container->get('io_service');
Expand Down Expand Up @@ -53,7 +54,7 @@ public function validateInstallDir($path): string
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this
->setName('install:vcs')
Expand Down Expand Up @@ -104,7 +105,7 @@ protected function configure()
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
/** @var Vcs $installService */
$installService = $this->container->get('shopware_vcs_install_service');
Expand All @@ -117,14 +118,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
$input->getOption('user'),
$input->getOption('noDemoData')
);

return Command::SUCCESS;
}

/**
* Try to guess a proper name (swTICKETNUMBER) from the branch name
*
* @param string $branch
*/
private function suggestNameFromBranch($branch): string
private function suggestNameFromBranch(string $branch): string
{
$result = [];
$pattern = '#sw-(?P<number>.+?)/(?P<target>.+?)/.*#i';
Expand All @@ -137,10 +138,7 @@ private function suggestNameFromBranch($branch): string
return \str_replace('.', '', $branch);
}

/**
* @param string $suggestion
*/
private function askInstallationDir(InputInterface $input, IoService $ioService, $suggestion): string
private function askInstallationDir(InputInterface $input, IoService $ioService, string $suggestion): string
{
$installDir = $input->getOption('installDir');
if (!$installDir) {
Expand All @@ -156,10 +154,7 @@ private function askInstallationDir(InputInterface $input, IoService $ioService,
return $installDir;
}

/**
* @param string $suggestion
*/
private function askDatabaseName(InputInterface $input, IoService $ioService, $suggestion): void
private function askDatabaseName(InputInterface $input, IoService $ioService, string $suggestion): void
{
$databaseName = $input->getOption('databaseName');
if (!$databaseName) {
Expand All @@ -168,10 +163,7 @@ private function askDatabaseName(InputInterface $input, IoService $ioService, $s
}
}

/**
* @param string $suggestion
*/
private function askBasePath(InputInterface $input, IoService $ioService, $suggestion): void
private function askBasePath(InputInterface $input, IoService $ioService, string $suggestion): void
{
$basePath = $input->getOption('basePath');
if (!$basePath) {
Expand Down

0 comments on commit 85c1e05

Please sign in to comment.