<commit_before><?php
declare(strict_types=1);

namespace Shlinkio\Shlink\CLI\Command\Tag;

use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException;
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Zend\I18n\Translator\TranslatorInterface;

class RenameTagCommand extends Command
{
    const NAME = 'tag:rename';

    /**
     * @var TagServiceInterface
     */
    private $tagService;
    /**
     * @var TranslatorInterface
     */
    private $translator;

    public function __construct(TagServiceInterface $tagService, TranslatorInterface $translator)
    {
        $this->tagService = $tagService;
        $this->translator = $translator;
        parent::__construct();
    }

    protected function configure()
    {
        $this
            ->setName(self::NAME)
            ->setDescription($this->translator->translate('Renames one existing tag.'))
            ->addArgument('oldName', InputArgument::REQUIRED, $this->translator->translate('Current name of the tag.'))
            ->addArgument('newName', InputArgument::REQUIRED, $this->translator->translate('New name of the tag.'));
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $oldName = $input->getArgument('oldName');
        $newName = $input->getArgument('newName');

        try {
            $this->tagService->renameTag($oldName, $newName);
            $output->writeln(sprintf('<info>%s</info>', $this->translator->translate('Tag properly renamed.')));
        } catch (EntityDoesNotExistException $e) {
            $output->writeln('<error>' . sprintf($this->translator->translate(
                'A tag with name "%s" was not found'
            ), $oldName) . '</error>');
        }
    }
}<commit_msg>Improved and simplified RenameTagCommand thanks to SymfonyStyle<commit_after><?php
declare(strict_types=1);

namespace Shlinkio\Shlink\CLI\Command\Tag;

use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException;
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Zend\I18n\Translator\TranslatorInterface;

class RenameTagCommand extends Command
{
    const NAME = 'tag:rename';

    /**
     * @var TagServiceInterface
     */
    private $tagService;
    /**
     * @var TranslatorInterface
     */
    private $translator;

    public function __construct(TagServiceInterface $tagService, TranslatorInterface $translator)
    {
        $this->tagService = $tagService;
        $this->translator = $translator;
        parent::__construct();
    }

    protected function configure()
    {
        $this
            ->setName(self::NAME)
            ->setDescription($this->translator->translate('Renames one existing tag.'))
            ->addArgument('oldName', InputArgument::REQUIRED, $this->translator->translate('Current name of the tag.'))
            ->addArgument('newName', InputArgument::REQUIRED, $this->translator->translate('New name of the tag.'));
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $io = new SymfonyStyle($input, $output);
        $oldName = $input->getArgument('oldName');
        $newName = $input->getArgument('newName');

        try {
            $this->tagService->renameTag($oldName, $newName);
            $io->success($this->translator->translate('Tag properly renamed.'));
        } catch (EntityDoesNotExistException $e) {
            $io->error(\sprintf($this->translator->translate('A tag with name "%s" was not found'), $oldName));
        }
    }
}
{'fraction_non_alphanumeric': 0.13340045305814247, 'fraction_numerical': 0.0015101938082053865, 'mean_word_length': 3.396017699115044, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4281', 'n_tokens_mistral': 1131, 'n_tokens_neox': 1117, 'n_words': 206}