Completed
Push — develop ( 8109ce...b15e90 )
by Alejandro
17s queued 12s
created

ListDomainsCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 14
dl 0
loc 31
ccs 15
cts 15
cp 1
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A configure() 0 5 1
A execute() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\CLI\Command\Domain;
6
7
use Shlinkio\Shlink\CLI\Util\ExitCodes;
8
use Shlinkio\Shlink\CLI\Util\ShlinkTable;
9
use Shlinkio\Shlink\Core\Domain\DomainServiceInterface;
10
use Shlinkio\Shlink\Core\Entity\Domain;
11
use Symfony\Component\Console\Command\Command;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
use function Functional\map;
16
17
class ListDomainsCommand extends Command
18
{
19
    public const NAME = 'domain:list';
20
21
    private DomainServiceInterface $domainService;
22
    private string $defaultDomain;
23
24 1
    public function __construct(DomainServiceInterface $domainService, string $defaultDomain)
25
    {
26 1
        parent::__construct();
27 1
        $this->domainService = $domainService;
28 1
        $this->defaultDomain = $defaultDomain;
29 1
    }
30
31 1
    protected function configure(): void
32
    {
33
        $this
34 1
            ->setName(self::NAME)
35 1
            ->setDescription('List all domains that have been ever used for some short URL');
36 1
    }
37
38 1
    protected function execute(InputInterface $input, OutputInterface $output): ?int
39
    {
40 1
        $regularDomains = $this->domainService->listDomainsWithout($this->defaultDomain);
41
42 1
        ShlinkTable::fromOutput($output)->render(['Domain', 'Is default'], [
43 1
            [$this->defaultDomain, 'Yes'],
44 1
            ...map($regularDomains, fn (Domain $domain) => [$domain->getAuthority(), 'No']),
45
        ]);
46
47 1
        return ExitCodes::EXIT_SUCCESS;
48
    }
49
}
50