Completed
Pull Request — master (#13)
by Andreas
05:52
created

CompareCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 27.87 %

Coupling/Cohesion

Components 0
Dependencies 11

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 6
c 2
b 0
f 2
lcom 0
cbo 11
dl 17
loc 61
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 10 1
B execute() 17 46 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 Symfony\Component\Console\Command\Command;
40
use Symfony\Component\Console\Input\InputArgument;
41
use Symfony\Component\Console\Input\InputInterface;
42
use Symfony\Component\Console\Output\Output;
43
use Symfony\Component\Console\Output\OutputInterface;
44
45
class CompareCommand extends Command
46
{
47
    protected function configure()
48
    {
49
        $this->setName('compare')
50
             ->setDescription('Compare two JUnit log files')
51
             ->setDefinition(array(
52
                 new InputArgument('input1', InputArgument::REQUIRED, 'First input file'),
53
                 new InputArgument('input2', InputArgument::REQUIRED, 'Second input file')
54
             ))
55
             ->setHelp('');
56
    }
57
58
59
    protected function execute(InputInterface $input, OutputInterface $output)
60
    {
61
        $style = new DiffStyle($input, $output);
62
        $style->title($this->getApplication()->getLongVersion());
63
64
65
        $parser = new JUnitParser($style);
0 ignored issues
show
Unused Code introduced by
The call to JUnitParser::__construct() has too many arguments starting with $style.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
66
        $merger = new JUnitMerger(new MergeResult($style));
67
        try {
68
            $mergeResult = $merger->merge(
69
                $parser->parseFile($input->getArgument('input1')),
70
                $parser->parseFile($input->getArgument('input2'))
71
            );
72
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);
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('input1')),
88
                basename($input->getArgument('input2'))
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('input1')),
97
                basename($input->getArgument('input2'))
98
            );
99
100
            $writer->write($mergeResult);
101
        }
102
103
104
    }
105
}
106