Passed
Push — master ( 527ce7...dff99b )
by Nils
02:47
created

CommandListCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 17
rs 10
1
<?php
2
3
namespace Startwind\Inventorio\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Helper\Table;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class CommandListCommand extends InventorioCommand
11
{
12
    protected static $defaultName = 'command:list';
13
    protected static $defaultDescription = 'List all registered commands';
14
15
    /**
16
     * @inheritDoc
17
     */
18
    protected function execute(InputInterface $input, OutputInterface $output): int
19
    {
20
        $this->initConfiguration($input->getOption('configFile'));
21
22
        $commands = $this->config->getCommands();
23
24
        $table = new Table($output);
25
26
        $table->setHeaders(['ID', 'Name', 'Command']);
27
28
        foreach ($commands as $id => $row) {
29
            $table->addRow([$id, $row['name'], $row['command']]);
30
        }
31
32
        $table->render();
33
34
        return Command::SUCCESS;
35
    }
36
}
37