ExportCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 31
c 2
b 0
f 0
dl 0
loc 54
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 21 1
A execute() 0 22 2
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
use Wowstack\Dbc\Mapping;
15
use Wowstack\Dbc\Export\XMLExport;
16
17
/**
18
 * @codeCoverageIgnore
19
 */
20
class ExportCommand extends Command
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    protected function configure()
26
    {
27
        $this
28
            ->setName('dbc:export')
29
            ->setDescription('Dumps the contents of a DBC file.')
30
            ->setHelp('This command allows you to dump any DBC file using a file map.')
31
            ;
32
33
        $this
34
            ->addArgument('file', InputArgument::REQUIRED, 'Path to the DBC file')
35
            ->addArgument('map', InputArgument::REQUIRED, 'Path to the YAML map')
36
            ->addArgument('xml', InputArgument::REQUIRED, 'Where to create the XML dump')
37
            ;
38
39
        $this
40
            ->addOption(
41
                'client-version',
42
                null,
43
                InputOption::VALUE_REQUIRED,
44
                'WoW client version',
45
                '1.12.1'
46
            );
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    protected function execute(InputInterface $input, OutputInterface $output)
53
    {
54
        $DBC = new DBC($input->getArgument('file'), Mapping::fromYAML($input->getArgument('map')));
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('map') 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

54
        $DBC = new DBC($input->getArgument('file'), Mapping::fromYAML(/** @scrutinizer ignore-type */ $input->getArgument('map')));
Loading history...
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

54
        $DBC = new DBC(/** @scrutinizer ignore-type */ $input->getArgument('file'), Mapping::fromYAML($input->getArgument('map')));
Loading history...
55
        $format = 'XML';
56
57
        $styledOutput = new SymfonyStyle($input, $output);
58
        $styledOutput->text([
59
            sprintf(
60
                'Dumping %s file contents in %s format to %s.',
61
                $DBC->getName(),
62
                $format,
63
                $input->getArgument('xml')
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('xml') can also be of type string[]; however, parameter $args of sprintf() 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

63
                /** @scrutinizer ignore-type */ $input->getArgument('xml')
Loading history...
64
            ),
65
            '',
66
        ]);
67
68
        $XMLExport = new XMLExport();
69
        $XMLExport->export($DBC, $input->getArgument('xml'), $input->getOption('client-version'));
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('xml') can also be of type null and string[]; however, parameter $targetPath of Wowstack\Dbc\Export\XMLExport::export() 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

69
        $XMLExport->export($DBC, /** @scrutinizer ignore-type */ $input->getArgument('xml'), $input->getOption('client-version'));
Loading history...
70
71
        foreach ($DBC->getErrors() as $error) {
72
            $output->writeln([
73
                '#'.$error['record'].' ('.$error['type'].'/'.$error['field'].'): '.$error['hint'],
0 ignored issues
show
Coding Style introduced by
Concat operator must be surrounded by a single space
Loading history...
74
            ]);
75
        }
76
    }
77
}
78