Completed
Pull Request — master (#98)
by Alejandro
06:29
created

CreateTagCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 12
loc 12
ccs 9
cts 9
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Shlinkio\Shlink\CLI\Command\Tag;
3
4
use Acelaya\ZsmAnnotatedServices\Annotation as DI;
5
use Shlinkio\Shlink\Core\Service\Tag\TagService;
6
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Zend\I18n\Translator\Translator;
12
use Zend\I18n\Translator\TranslatorInterface;
13
14 View Code Duplication
class CreateTagCommand extends Command
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
{
16
    /**
17
     * @var TagServiceInterface
18
     */
19
    private $tagService;
20
    /**
21
     * @var TranslatorInterface
22
     */
23
    private $translator;
24
25
    /**
26
     * CreateTagCommand constructor.
27
     * @param TagServiceInterface $tagService
28
     * @param TranslatorInterface $translator
29
     *
30
     * @DI\Inject({TagService::class, Translator::class})
31
     */
32 2
    public function __construct(TagServiceInterface $tagService, TranslatorInterface $translator)
33
    {
34 2
        $this->tagService = $tagService;
35 2
        $this->translator = $translator;
36 2
        parent::__construct();
37 2
    }
38
39 2
    protected function configure()
40
    {
41
        $this
42 2
            ->setName('tag:create')
43 2
            ->setDescription($this->translator->translate('Creates one or more tags.'))
44 2
            ->addOption(
45 2
                'name',
46 2
                't',
47 2
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
48 2
                $this->translator->translate('The name of the tags to create')
49
            );
50 2
    }
51
52 2
    protected function execute(InputInterface $input, OutputInterface $output)
53
    {
54 2
        $tagNames = $input->getOption('name');
55 2
        if (empty($tagNames)) {
56 1
            $output->writeln(sprintf(
57 1
                '<comment>%s</comment>',
58 1
                $this->translator->translate('You have to provide at least one tag name')
59
            ));
60 1
            return;
61
        }
62
63 1
        $this->tagService->createTags($tagNames);
64 1
        $output->writeln($this->translator->translate('Created tags') . sprintf(': ["<info>%s</info>"]', implode(
65 1
            '</info>", "<info>',
66 1
            $tagNames
67
        )));
68 1
    }
69
}
70