Passed
Push — bugfix/support-windows ( 0e99e7...b5ecf8 )
by Jesús
06:33 queued 02:55
created

ListModulesCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 30
ccs 17
cts 17
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 5 1
A execute() 0 19 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Console\Infrastructure\Command;
6
7
use Gacela\Console\ConsoleFacade;
8
use Gacela\Framework\DocBlockResolverAwareTrait;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Helper\Table;
11
use Symfony\Component\Console\Input\InputArgument;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
/**
16
 * @method ConsoleFacade getFacade()
17
 */
18
final class ListModulesCommand extends Command
19
{
20
    use DocBlockResolverAwareTrait;
21
22 4
    protected function configure(): void
23
    {
24 4
        $this->setName('list:modules')
25 4
            ->setDescription('Render all modules found')
26 4
            ->addArgument('filter', InputArgument::OPTIONAL, 'Any filter to simplify the output');
27
    }
28
29 3
    protected function execute(InputInterface $input, OutputInterface $output): int
30
    {
31 3
        $filter = (string)$input->getArgument('filter');
32 3
        $modules = $this->getFacade()->findAllAppModules($filter);
33
34 3
        $table = new Table($output);
35 3
        $table->setHeaders(['Module', 'Facade']);
36
37 3
        foreach ($modules as $module) {
38 3
            $table->addRow([
39 3
                $module->moduleName(),
40 3
                $module->facadeClass(),
41 3
            ]);
42
        }
43
44 3
        $output->writeln('Modules found:');
45 3
        $table->render();
46
47 3
        return self::SUCCESS;
48
    }
49
}
50