DisableKeyCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 16
dl 0
loc 31
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A configure() 0 5 1
A execute() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\CLI\Command\Api;
6
7
use Shlinkio\Shlink\CLI\Util\ExitCodes;
8
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
9
use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface;
10
use Symfony\Component\Console\Command\Command;
11
use Symfony\Component\Console\Input\InputArgument;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
use Symfony\Component\Console\Style\SymfonyStyle;
15
16
use function sprintf;
17
18
class DisableKeyCommand extends Command
19
{
20
    public const NAME = 'api-key:disable';
21
22
    private ApiKeyServiceInterface $apiKeyService;
23
24 2
    public function __construct(ApiKeyServiceInterface $apiKeyService)
25
    {
26 2
        parent::__construct();
27 2
        $this->apiKeyService = $apiKeyService;
28 2
    }
29
30 2
    protected function configure(): void
31
    {
32 2
        $this->setName(self::NAME)
33 2
             ->setDescription('Disables an API key.')
34 2
             ->addArgument('apiKey', InputArgument::REQUIRED, 'The API key to disable');
35 2
    }
36
37 2
    protected function execute(InputInterface $input, OutputInterface $output): ?int
38
    {
39 2
        $apiKey = $input->getArgument('apiKey');
40 2
        $io = new SymfonyStyle($input, $output);
41
42
        try {
43 2
            $this->apiKeyService->disable($apiKey);
0 ignored issues
show
Bug introduced by
It seems like $apiKey can also be of type null and string[]; however, parameter $key of Shlinkio\Shlink\Rest\Ser...iceInterface::disable() 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

43
            $this->apiKeyService->disable(/** @scrutinizer ignore-type */ $apiKey);
Loading history...
44 1
            $io->success(sprintf('API key "%s" properly disabled', $apiKey));
0 ignored issues
show
Bug introduced by
It seems like $apiKey can also be of type string[]; however, parameter $args of sprintf() 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

44
            $io->success(sprintf('API key "%s" properly disabled', /** @scrutinizer ignore-type */ $apiKey));
Loading history...
45 1
            return ExitCodes::EXIT_SUCCESS;
46 1
        } catch (InvalidArgumentException $e) {
47 1
            $io->error($e->getMessage());
48 1
            return ExitCodes::EXIT_FAILURE;
49
        }
50
    }
51
}
52