Completed
Push — master ( 236db5...b6d10e )
by Pablo
7s
created

PrePushProcessor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 22.81 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 5
c 4
b 1
f 0
lcom 1
cbo 7
dl 13
loc 57
ccs 18
cts 18
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A configTools() 0 10 1
A process() 13 13 3

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
namespace PhpGitHooks\Module\Configuration\Service;
4
5
use Composer\IO\IOInterface;
6
use PhpGitHooks\Module\Configuration\Domain\Execute;
7
use PhpGitHooks\Module\Configuration\Domain\PrePush;
8
use PhpGitHooks\Module\Configuration\Model\ExecuteInterface;
9
10
class PrePushProcessor
11
{
12
    /**
13
     * @var IOInterface
14
     */
15
    private $input;
16
    /**
17
     * @var PhpUnitGuardCoverageConfigurator
18
     */
19
    private $phpUnitGuardCoverageConfigurator;
20
21
    /**
22
     * PrePushProcessor constructor.
23
     *
24
     * @param PhpUnitGuardCoverageConfigurator $phpUnitGuardCoverageConfigurator
25
     */
26 2
    public function __construct(PhpUnitGuardCoverageConfigurator $phpUnitGuardCoverageConfigurator)
27
    {
28 2
        $this->phpUnitGuardCoverageConfigurator = $phpUnitGuardCoverageConfigurator;
29 2
    }
30
31
    /**
32
     * @param PrePush     $prePushData
33
     * @param IOInterface $input
34
     *
35
     * @return PrePush
36
     */
37 2 View Code Duplication
    public function process(PrePush $prePushData, IOInterface $input)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
38
    {
39 2
        $this->input = $input;
40 2
        if (true === $prePushData->isUndefined()) {
41 1
            $prePushData = PrePushConfigurator::configure($this->input, $prePushData);
42 1
        }
43
44 2
        if (true === $prePushData->isEnabled()) {
45 2
            $prePushData = $prePushData->setExecute($this->configTools($prePushData->getExecute()));
46 2
        }
47
48 2
        return $prePushData;
49
    }
50
51
    /**
52
     * @param ExecuteInterface $execute
53
     *
54
     * @return Execute
55
     */
56 2
    protected function configTools(ExecuteInterface $execute)
57
    {
58 2
        $tools = $execute->execute();
59
60 2
        $tools[0] = PhpUnitConfigurator::configure($this->input, $tools[0]);
0 ignored issues
show
Compatibility introduced by
$tools[0] of type object<PhpGitHooks\Modul...on\Model\ToolInterface> is not a sub-type of object<PhpGitHooks\Modul...uration\Domain\PhpUnit>. It seems like you assume a concrete implementation of the interface PhpGitHooks\Module\Confi...ion\Model\ToolInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
61 2
        $tools[1] = PhpUnitStrictCoverageConfigurator::configure($this->input, $tools[1]);
62 2
        $tools[2] = $this->phpUnitGuardCoverageConfigurator->configure($this->input, $tools[2]);
63
64 2
        return new  Execute($tools);
65
    }
66
}
67