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
|
|
|
$isoCodePath = __DIR__.'/../../../vendor/ronanguilloux/isocodes'; |
33
|
|
|
if (!file_exists($isoCodePath.'/.git')) { |
34
|
|
|
$output->writeln( |
35
|
|
|
'<error>No .git folder found on ronanguilloux/isocodes package. Please remove vendor folder and run composer update ronanguilloux/isocodes --prefer-source command.</error>' |
|
|
|
|
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
return 1; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$fqcnRepository = new FqcnRepository(new FileRepository(), new ParserFactory()); |
42
|
|
|
|
43
|
|
|
$isoCodesClasses = array_map(function ($fqcn) { |
44
|
|
|
return str_replace('IsoCodes\\', '', $fqcn); |
45
|
|
|
}, $fqcnRepository->findIn(__DIR__.'/../../../vendor/ronanguilloux/isocodes/src/IsoCodes')); |
46
|
|
|
|
47
|
|
|
$constraintClasses = array_filter(array_map(function ($fqcn) { |
48
|
|
|
return str_replace('SLLH\\IsoCodesValidator\\Constraints\\', '', $fqcn); |
49
|
|
|
}, $fqcnRepository->findIn(__DIR__.'/../../../src/Constraints')), function ($className) { |
50
|
|
|
return !empty(trim($className)); |
51
|
|
|
}); |
52
|
|
|
|
53
|
|
|
foreach (array_udiff($isoCodesClasses, $constraintClasses, 'strcasecmp') as $className) { |
54
|
|
|
$classVersion = str_replace( |
55
|
|
|
'v', |
56
|
|
|
'', |
57
|
|
|
exec("cd ${isoCodePath} && git tag --list --contains $(git log --pretty=format:\"%h\" --diff-filter=A src/IsoCodes/${className}.php) | head -n 1") |
|
|
|
|
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
$output->writeln("Generate <comment>${className}</comment> constraint (<info>v${classVersion}</info>)."); |
61
|
|
|
|
62
|
|
|
// Find class first version: git tag --list --contains $(git log --pretty=format:"%h" --diff-filter=A UPGRADE-1.1.md) | head -n 1 |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return 0; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.