ListCommand::__construct()   A
last analyzed

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\Component\Console\Command\Command;
8
use Symfony\Component\Console\Helper\Table;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class ListCommand extends Command
13
{
14
15
    /**
16
     * @var ImporterRepository
17
     */
18
    private $importerRepository;
19
20
    public function __construct(ImporterRepository $importerRepository)
21
    {
22
        parent::__construct('importengine:list');
23
24
        $this->importerRepository = $importerRepository;
25
    }
26
27
    protected function configure()
28
    {
29
        $this->setDescription('Lists all available importer');
30
    }
31
32
    protected function execute(InputInterface $input, OutputInterface $output)
33
    {
34
        $table = new Table($output);
35
        $table->setHeaders(['id', 'auto-detectable', 'validation']);
36
37
        foreach ($this->importerRepository->getIds() as $importerId) {
38
            $importer = $this->importerRepository->get($importerId);
39
40
            $table->addRow([
41
                $importerId,
42
                $this->importerRepository->hasPrecondition($importerId) ? 'Yes' : 'No',
43
                ($importer->validation() instanceof DummyValidation) ? 'No' : 'Yes',
44
            ]);
45
        }
46
47
        $table->render();
48
    }
49
}
50