Improved and simplified ListTagsCommand thanks to SymfonyStyle

This commit is contained in:
Alejandro Celaya 2017-12-31 19:08:10 +01:00
parent 057bbae729
commit 7856d64299

View file

@ -6,9 +6,9 @@ namespace Shlinkio\Shlink\CLI\Command\Tag;
use Shlinkio\Shlink\Core\Entity\Tag;
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Zend\I18n\Translator\TranslatorInterface;
class ListTagsCommand extends Command
@ -40,11 +40,8 @@ class ListTagsCommand extends Command
protected function execute(InputInterface $input, OutputInterface $output)
{
$table = new Table($output);
$table->setHeaders([$this->translator->translate('Name')])
->setRows($this->getTagsRows());
$table->render();
$io = new SymfonyStyle($input, $output);
$io->table([$this->translator->translate('Name')], $this->getTagsRows());
}
private function getTagsRows()
@ -54,7 +51,7 @@ class ListTagsCommand extends Command
return [[$this->translator->translate('No tags yet')]];
}
return array_map(function (Tag $tag) {
return \array_map(function (Tag $tag) {
return [$tag->getName()];
}, $tags);
}