1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Wowstack\Dbc\Command; |
||
6 | |||
7 | use Symfony\Component\Console\Command\Command; |
||
8 | use Symfony\Component\Console\Input\InputArgument; |
||
9 | use Symfony\Component\Console\Input\InputInterface; |
||
10 | use Symfony\Component\Console\Output\OutputInterface; |
||
11 | use Symfony\Component\Console\Helper\Table; |
||
12 | use Symfony\Component\Console\Style\SymfonyStyle; |
||
13 | use Wowstack\Dbc\Mapping; |
||
14 | |||
15 | /** |
||
16 | * @codeCoverageIgnore |
||
17 | */ |
||
18 | class MapCheckCommand extends Command |
||
19 | { |
||
20 | /** |
||
21 | * {@inheritdoc} |
||
22 | */ |
||
23 | protected function configure() |
||
24 | { |
||
25 | $this |
||
26 | ->setName('map:check') |
||
27 | ->setDescription('Checks a map.') |
||
28 | ->setHelp('This command loads a mapping file and check if it loads.') |
||
29 | ; |
||
30 | |||
31 | $this |
||
32 | ->addArgument('file', InputArgument::REQUIRED, 'Path to the map file') |
||
33 | ; |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | protected function execute(InputInterface $input, OutputInterface $output) |
||
40 | { |
||
41 | $Map = Mapping::fromYAML($input->getArgument('file')); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
42 | |||
43 | $io = new SymfonyStyle($input, $output); |
||
44 | $table = new Table($output); |
||
45 | $io->title('DBC Inspect'); |
||
46 | $io->section('Stats'); |
||
47 | $io->text([ |
||
48 | sprintf( |
||
49 | 'The mapping contains %u fields at %u bytes in total.', |
||
50 | $Map->getFieldCount(), |
||
0 ignored issues
–
show
|
|||
51 | $Map->getFieldSize() |
||
0 ignored issues
–
show
|
|||
52 | ), |
||
53 | '', |
||
54 | ]); |
||
55 | |||
56 | $io->newLine(); |
||
57 | |||
58 | $io->section('Fields'); |
||
59 | $table->setHeaders($Map->getFieldNames()); |
||
0 ignored issues
–
show
|
|||
60 | $parsed_fields = $Map->getParsedFields(); |
||
0 ignored issues
–
show
|
|||
61 | $field_types = []; |
||
0 ignored issues
–
show
|
|||
62 | foreach ($parsed_fields as $field_name => $field_data) { |
||
0 ignored issues
–
show
|
|||
63 | $field_types[] = $field_data['type']; |
||
0 ignored issues
–
show
|
|||
64 | } |
||
65 | $table->addRow($field_types); |
||
0 ignored issues
–
show
|
|||
66 | $table->render(); |
||
67 | } |
||
68 | } |
||
69 |