CompareCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Copyright (c) Andreas Heigl<[email protected]>
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining a copy
6
 * of this software and associated documentation files (the "Software"), to deal
7
 * in the Software without restriction, including without limitation the rights
8
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the Software is
10
 * furnished to do so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be included in
13
 * all copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
 * THE SOFTWARE.
22
 *
23
 * @author    Andreas Heigl<[email protected]>
24
 * @copyright Andreas Heigl
25
 * @license   http://www.opensource.org/licenses/mit-license.php MIT-License
26
 * @since     14.06.2016
27
 * @link      http://github.com/heiglandreas/org.heigl.junitdiff
28
 */
29
30
namespace Org_Heigl\JUnitDiff\Command;
31
32
use Org_Heigl\JUnitDiff\JUnitMerger;
33
use Org_Heigl\JUnitDiff\JUnitParser;
34
use Org_Heigl\JUnitDiff\MergeResult;
35
use Org_Heigl\JUnitDiff\Style\DiffStyle;
36
use Org_Heigl\JUnitDiff\Writer\FileSummary;
37
use Org_Heigl\JUnitDiff\Writer\Legend;
38
use Org_Heigl\JUnitDiff\Writer\Standard;
39
use Org_Heigl\JUnitDiff\Writer\Quiet;
40
use Org_Heigl\JUnitDiff\Writer\Summary;
41
use Symfony\Component\Console\Command\Command;
42
use Symfony\Component\Console\Input\InputArgument;
43
use Symfony\Component\Console\Input\InputInterface;
44
use Symfony\Component\Console\Output\Output;
45
use Symfony\Component\Console\Output\OutputInterface;
46
47
class CompareCommand extends Command
48
{
49
    protected function configure()
50
    {
51
        $this->setName('compare')
52
             ->setDescription('Compares two JUnit log files')
53
             ->setDefinition([
54
                 new InputArgument('base', InputArgument::REQUIRED, 'Base file for the comparison'),
55
                 new InputArgument('current', InputArgument::REQUIRED, 'Current file to compare against the base file')
56
             ])
57
             ->setHelp('');
58
    }
59
60
61
    protected function execute(InputInterface $input, OutputInterface $output)
62
    {
63
        $style = new DiffStyle($input, $output);
64
        $style->title($this->getApplication()->getLongVersion());
65
66
67
        $parser = new JUnitParser();
68
        $merger = new JUnitMerger(new MergeResult($style));
69
        try {
70
            $mergeResult = $merger->merge(
71
                $parser->parseFile($input->getArgument('base')),
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('base') targeting Symfony\Component\Consol...nterface::getArgument() can also be of type array<integer,string> or null; however, Org_Heigl\JUnitDiff\JUnitParser::parseFile() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
72
                $parser->parseFile($input->getArgument('current'))
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('current') targeting Symfony\Component\Consol...nterface::getArgument() can also be of type array<integer,string> or null; however, Org_Heigl\JUnitDiff\JUnitParser::parseFile() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
73
            );
74
        } catch (\Exception $e) {
75
            $style->error($e->getMessage());
76
            return;
77
        }
78
79
        if ($output->getVerbosity() >= Output::VERBOSITY_NORMAL) {
80
            $writer = new Standard($style, $output->getVerbosity());
81
            $writer->write($mergeResult);
82
        }
83
84 View Code Duplication
        if ($output->getVerbosity() >= Output::VERBOSITY_VERBOSE) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
85
            $writer = new Legend(
86
                $style,
87
                basename($input->getArgument('base')),
88
                basename($input->getArgument('current'))
89
            );
90
            $writer->write($mergeResult);
91
        }
92
93 View Code Duplication
        if ($output->getVerbosity() >= Output::VERBOSITY_QUIET) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
            $writer = new FileSummary(
95
                $style,
96
                basename($input->getArgument('base')),
97
                basename($input->getArgument('current'))
98
            );
99
100
            $writer->write($mergeResult);
101
        }
102
103 View Code Duplication
        if ($output->getVerbosity() >= Output::VERBOSITY_QUIET) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
104
            $writer = new Summary(
105
                $style,
106
                basename($input->getArgument('base')),
107
                basename($input->getArgument('current'))
108
            );
109
            $writer->write($mergeResult);
110
        }
111
    }
112
}
113