Completed
Push — master ( e21ac0...e43437 )
by Markus
05:40
created

ListCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Mathielen\ImportEngineBundle\Command;
4
5
use Mathielen\ImportEngine\Importer\ImporterRepository;
6
use Mathielen\ImportEngine\Validation\DummyValidation;
7
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Helper\Table;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
class ListCommand extends Command
14
{
15
16
    /**
17
     * @var ImporterRepository
18
     */
19
    private $importerRepository;
20
21
    public function __construct(ImporterRepository $importerRepository)
22
    {
23
        parent::__construct('importengine:list');
24
25
        $this->importerRepository = $importerRepository;
26
    }
27
28
    protected function configure()
29
    {
30
        $this->setDescription('Lists all available importer');
31
    }
32
33
    protected function execute(InputInterface $input, OutputInterface $output)
34
    {
35
        $table = new Table($output);
36
        $table->setHeaders(['id', 'auto-detectable', 'validation']);
37
38
        foreach ($this->importerRepository->getIds() as $importerId) {
39
            $importer = $this->importerRepository->get($importerId);
40
41
            $table->addRow([
42
                $importerId,
43
                $this->importerRepository->hasPrecondition($importerId) ? 'Yes' : 'No',
44
                ($importer->validation() instanceof DummyValidation) ? 'No' : 'Yes',
45
            ]);
46
        }
47
48
        $table->render();
49
    }
50
}
51