Issues (76)

src/Command/MapCheckCommand.php (14 issues)

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
It seems like $input->getArgument('file') can also be of type null and string[]; however, parameter $yaml of Wowstack\Dbc\Mapping::fromYAML() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

41
        $Map = Mapping::fromYAML(/** @scrutinizer ignore-type */ $input->getArgument('file'));
Loading history...
Variable "Map" is not in valid camel caps format
Loading history...
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
Variable "Map" is not in valid camel caps format
Loading history...
51
                $Map->getFieldSize()
0 ignored issues
show
Variable "Map" is not in valid camel caps format
Loading history...
52
            ),
53
            '',
54
        ]);
55
56
        $io->newLine();
57
58
        $io->section('Fields');
59
        $table->setHeaders($Map->getFieldNames());
0 ignored issues
show
Variable "Map" is not in valid camel caps format
Loading history...
60
        $parsed_fields = $Map->getParsedFields();
0 ignored issues
show
Variable "parsed_fields" is not in valid camel caps format
Loading history...
Variable "Map" is not in valid camel caps format
Loading history...
61
        $field_types = [];
0 ignored issues
show
Variable "field_types" is not in valid camel caps format
Loading history...
62
        foreach ($parsed_fields as $field_name => $field_data) {
0 ignored issues
show
Variable "parsed_fields" is not in valid camel caps format
Loading history...
Variable "field_name" is not in valid camel caps format
Loading history...
Variable "field_data" is not in valid camel caps format
Loading history...
63
            $field_types[] = $field_data['type'];
0 ignored issues
show
Variable "field_types" is not in valid camel caps format
Loading history...
Variable "field_data" is not in valid camel caps format
Loading history...
64
        }
65
        $table->addRow($field_types);
0 ignored issues
show
Variable "field_types" is not in valid camel caps format
Loading history...
66
        $table->render();
67
    }
68
}
69