Command   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 0
loc 58
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B configure() 0 30 1
A getParameters() 0 13 3
A execute() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of gpupo/pipe2
5
 *
6
 * (c) Gilmar Pupo <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * For more information, see
12
 * <https://opensource.gpupo.com/pipe2/>.
13
 */
14
15
namespace Gpupo\Pipe2\Merge\Attributes;
16
17
use Symfony\Component\Console\Command\Command as Core;
18
use Symfony\Component\Console\Input\InputArgument;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Input\InputOption;
21
use Symfony\Component\Console\Output\OutputInterface;
22
23
class Command extends Core
24
{
25
    protected function configure()
26
    {
27
        parent::configure();
28
        $this
29
            ->setName('merge-attributes')
30
            ->setDescription('Merge XML Documents with Similar Structure Where Second Document Contains Attributes')
31
            ->addArgument(
32
                'firstDocument',
33
                InputArgument::REQUIRED,
34
                'First Document Xml file path'
35
            )
36
            ->addArgument(
37
                'secondDocument',
38
                InputArgument::REQUIRED,
39
                'Second Document Xml file path'
40
            )
41
            ->addOption(
42
                'idField',
43
                null,
44
                InputOption::VALUE_OPTIONAL,
45
                'Item field to fill document id',
46
                'id'
47
            )->addOption(
48
                'pretty',
49
                null,
50
                InputOption::VALUE_OPTIONAL,
51
                'Nicely formats output with indentation and extra space',
52
                false
53
            );
54
    }
55
56
    protected function getParameters(InputInterface $input)
57
    {
58
        $parameters = [
59
            'idField'       => $input->getOption('idField'),
60
            'formatOutput'  => ($input->getOption('pretty') === 'true') ? true : false,
61
        ];
62
63
        foreach (['firstDocument', 'secondDocument'] as $argument) {
64
            $parameters[$argument] = $input->getArgument($argument);
65
        }
66
67
        return $parameters;
68
    }
69
70
    protected function execute(InputInterface $input, OutputInterface $output)
71
    {
72
        $parameters = $this->getParameters($input);
73
        $validator = new InputValidator();
74
75
        if ($validator->validateInputParameters($parameters)) {
76
            $combiner = new Combiner($parameters);
77
            $output->writeln($combiner->getDocument()->saveXml());
78
        }
79
    }
80
}
81