Completed
Push — generator ( 4d6c7f )
by Sullivan
06:27
created

GenerateCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 11
nc 2
nop 2
1
<?php
2
3
namespace SLLH\IsoCodesValidator\Dev\Console\Command;
4
5
use Gnugat\NomoSpaco\File\FileRepository;
6
use Gnugat\NomoSpaco\FqcnRepository;
7
use Gnugat\NomoSpaco\Token\ParserFactory;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
/**
13
 * @author Sullivan Senechal <[email protected]>
14
 */
15
final class GenerateCommand extends Command
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    protected function configure()
21
    {
22
        $this
23
            ->setName('generate')
24
        ;
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected function execute(InputInterface $input, OutputInterface $output)
31
    {
32
        $fqcnRepository = new FqcnRepository(new FileRepository(), new ParserFactory());
33
34
        $isoCodesClasses = array_map(function ($fqcn) {
35
            return str_replace('IsoCodes\\', '', $fqcn);
36
        }, $fqcnRepository->findIn(__DIR__.'/../../../vendor/ronanguilloux/isocodes/src/IsoCodes'));
37
38
        $constraintClasses = array_filter(array_map(function ($fqcn) {
39
            return str_replace('SLLH\\IsoCodesValidator\\Constraints\\', '', $fqcn);
40
        }, $fqcnRepository->findIn(__DIR__.'/../../../src/Constraints')), function ($className) {
41
            return !empty(trim($className));
42
        });
43
44
        foreach (array_udiff($isoCodesClasses, $constraintClasses, 'strcasecmp') as $missingConstraint) {
45
            $output->writeln("Generate <comment>${missingConstraint}</comment> constraint.");
46
        }
47
    }
48
}
49