RenameTagCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
ccs 5
cts 5
cp 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\CLI\Command\Tag;
6
7
use Shlinkio\Shlink\CLI\Util\ExitCodes;
8
use Shlinkio\Shlink\Core\Exception\TagConflictException;
9
use Shlinkio\Shlink\Core\Exception\TagNotFoundException;
10
use Shlinkio\Shlink\Core\Tag\TagServiceInterface;
11
use Symfony\Component\Console\Command\Command;
12
use Symfony\Component\Console\Input\InputArgument;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Output\OutputInterface;
15
use Symfony\Component\Console\Style\SymfonyStyle;
16
17
class RenameTagCommand extends Command
18
{
19
    public const NAME = 'tag:rename';
20
21
    private TagServiceInterface $tagService;
22
23 2
    public function __construct(TagServiceInterface $tagService)
24
    {
25 2
        parent::__construct();
26 2
        $this->tagService = $tagService;
27 2
    }
28
29 2
    protected function configure(): void
30
    {
31
        $this
32 2
            ->setName(self::NAME)
33 2
            ->setDescription('Renames one existing tag.')
34 2
            ->addArgument('oldName', InputArgument::REQUIRED, 'Current name of the tag.')
35 2
            ->addArgument('newName', InputArgument::REQUIRED, 'New name of the tag.');
36 2
    }
37
38 2
    protected function execute(InputInterface $input, OutputInterface $output): ?int
39
    {
40 2
        $io = new SymfonyStyle($input, $output);
41 2
        $oldName = $input->getArgument('oldName');
42 2
        $newName = $input->getArgument('newName');
43
44
        try {
45 2
            $this->tagService->renameTag($oldName, $newName);
0 ignored issues
show
Bug introduced by
It seems like $oldName can also be of type null and string[]; however, parameter $oldName of Shlinkio\Shlink\Core\Tag...eInterface::renameTag() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
            $this->tagService->renameTag(/** @scrutinizer ignore-type */ $oldName, $newName);
Loading history...
Bug introduced by
It seems like $newName can also be of type null and string[]; however, parameter $newName of Shlinkio\Shlink\Core\Tag...eInterface::renameTag() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
            $this->tagService->renameTag($oldName, /** @scrutinizer ignore-type */ $newName);
Loading history...
46 1
            $io->success('Tag properly renamed.');
47 1
            return ExitCodes::EXIT_SUCCESS;
48 1
        } catch (TagNotFoundException | TagConflictException $e) {
49 1
            $io->error($e->getMessage());
50 1
            return ExitCodes::EXIT_FAILURE;
51
        }
52
    }
53
}
54