Skip to content

Commit

Permalink
Update commands:
Browse files Browse the repository at this point in the history
- improve inheritance
  • Loading branch information
webeweb committed May 28, 2024
1 parent a5014d1 commit 95c866a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 31 deletions.
37 changes: 7 additions & 30 deletions src/Command/ListStorageProviderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,23 @@

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use WBW\Bundle\CommonBundle\Command\AbstractProviderListCommand;
use WBW\Bundle\EDMBundle\Manager\StorageManagerTrait;
use WBW\Bundle\EDMBundle\Provider\StorageProviderInterface;
use WBW\Bundle\EDMBundle\WBWEDMBundle;

/**
* List storage provider command.
*
* @author webeweb <https://github.com/webeweb>
* @package WBW\Bundle\EDMBundle\Command
*/
class ListStorageProviderCommand extends AbstractCommand {
class ListStorageProviderCommand extends AbstractProviderListCommand {

use StorageManagerTrait {
setStorageManager as public;
}

/**
* Command help.
*
* @var string
*/
const COMMAND_HELP = <<< EOT
The <info>%command.name%</info> command list the storage providers.
<info>php %command.full_name%</info>
EOT;

/**
* Command name.
*
Expand All @@ -63,14 +52,14 @@ class ListStorageProviderCommand extends AbstractCommand {
protected function configure(): void {
$this
->setDescription("List the storage providers")
->setHelp(self::COMMAND_HELP)
->setHelp(static::formatHelp("list the storage providers"))
->setName(self::COMMAND_NAME);
}

/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): ?int {
protected function execute(InputInterface $input, OutputInterface $output): int {

$io = $this->newStyle($input, $output);
$this->displayTitle($io, $this->getDescription());
Expand All @@ -85,6 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
$this->sortRows($rows);

$io->table($this->getHeaders(), $rows);
$this->displayFooter($io, count($rows), "command.footer.provider_list.success", "command.footer.provider_list.warning", WBWEDMBundle::getTranslationDomain(), "en");

return 0;
}
Expand All @@ -97,7 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
protected function getHeaders(): array {

return [
$this->translate("label.class", [], null, "en"),
$this->translate("command.header.class", [], WBWEDMBundle::getTranslationDomain(), "en"),
];
}

Expand All @@ -113,17 +103,4 @@ protected function renderRow(StorageProviderInterface $provider): array {
get_class($provider),
];
}

/**
* Sort the rows.
*
* @param string[][] $rows The rows.
* @return void
*/
protected function sortRows(array &$rows): void {

usort($rows, function(array $a, array $b) {
return strcmp($a[0], $b[0]);
});
}
}
2 changes: 1 addition & 1 deletion tests/Command/ListStorageProviderCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function test__construct(): void {
$obj = new ListStorageProviderCommand();

$this->assertEquals("List the storage providers", $obj->getDescription());
$this->assertEquals(ListStorageProviderCommand::COMMAND_HELP, $obj->getHelp());
$this->assertNotNull($obj->getHelp());
$this->assertEquals(ListStorageProviderCommand::COMMAND_NAME, $obj->getName());
}
}

0 comments on commit 95c866a

Please sign in to comment.