InspectCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 42
c 3
b 0
f 0
dl 0
loc 71
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 41 4
A configure() 0 19 1
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\Input\InputOption;
11
use Symfony\Component\Console\Output\OutputInterface;
12
use Symfony\Component\Console\Style\SymfonyStyle;
13
use Wowstack\Dbc\DBC;
14
15
/**
16
 * @codeCoverageIgnore
17
 */
18
class InspectCommand extends Command
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    protected function configure()
24
    {
25
        $this
26
            ->setName('dbc:inspect')
27
            ->setDescription('Inspect a DBC file.')
28
            ->setHelp('This command allows you to inspect any DBC file and receive basic information about it.')
29
            ;
30
31
        $this
32
            ->addArgument('file', InputArgument::REQUIRED, 'Path to the DBC file')
33
            ;
34
35
        $this
36
            ->addOption(
37
                'string-samples',
38
                null,
39
                InputOption::VALUE_REQUIRED,
40
                'Print selected number of string samples',
41
                10
42
            );
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    protected function execute(InputInterface $input, OutputInterface $output)
49
    {
50
        $DBC = new DBC($input->getArgument('file'));
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('file') can also be of type null and string[]; however, parameter $path of Wowstack\Dbc\DBC::__construct() 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

50
        $DBC = new DBC(/** @scrutinizer ignore-type */ $input->getArgument('file'));
Loading history...
51
52
        $io = new SymfonyStyle($input, $output);
53
        $io->title('DBC Inspect');
54
        $io->section('Stats');
55
        $io->text([
56
            sprintf(
57
                'The %s file contains %u rows at %u bytes per column, split into %u fields.',
58
                $DBC->getName(),
59
                $DBC->getRecordCount(),
60
                $DBC->getRecordSize(),
61
                $DBC->getFieldCount()
62
            ),
63
            '',
64
        ]);
65
66
        if ($DBC->hasStrings()) {
67
            $string_block = $DBC->getStringBlock();
0 ignored issues
show
Coding Style introduced by
Variable "string_block" is not in valid camel caps format
Loading history...
68
            $io->section('Strings');
69
            $io->text([
70
                sprintf(
71
                    'The %s file contains %u strings.',
72
                    $DBC->getName(),
73
                    count($string_block)
0 ignored issues
show
Coding Style introduced by
Variable "string_block" is not in valid camel caps format
Loading history...
74
                ),
75
                '',
76
            ]);
77
78
            $string_samples = $input->getOption('string-samples');
0 ignored issues
show
Coding Style introduced by
Variable "string_samples" is not in valid camel caps format
Loading history...
79
80
            foreach ($string_block as $index => $string) {
0 ignored issues
show
Coding Style introduced by
Variable "string_block" is not in valid camel caps format
Loading history...
81
                $io->text([$index.': '.$string]);
0 ignored issues
show
Coding Style introduced by
Concat operator must be surrounded by a single space
Loading history...
82
                --$string_samples;
0 ignored issues
show
Coding Style introduced by
Variable "string_samples" is not in valid camel caps format
Loading history...
83
                if (0 === $string_samples) {
0 ignored issues
show
Coding Style introduced by
Variable "string_samples" is not in valid camel caps format
Loading history...
84
                    break;
85
                }
86
            }
87
        }
88
        $io->newLine();
89
    }
90
}
91