Completed
Push — master ( 8ee32e...efc44e )
by Pablo
02:33
created

getConfigurationDataResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 51
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 1.0698

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 51
rs 9.4109
ccs 20
cts 34
cp 0.5881
cc 1
eloc 34
nc 1
nop 1
crap 1.0698

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace PhpGitHooks\Module\Configuration\Contract\Query;
4
5
use Bruli\EventBusBundle\QueryBus\QueryHandlerInterface;
6
use Bruli\EventBusBundle\QueryBus\QueryInterface;
7
use PhpGitHooks\Infrastructure\Hook\PrePush;
8
use PhpGitHooks\Module\Configuration\Contract\Response\ConfigurationDataResponse;
9
use PhpGitHooks\Module\Configuration\Domain\CommitMsg;
10
use PhpGitHooks\Module\Configuration\Domain\Config;
11
use PhpGitHooks\Module\Configuration\Domain\PhpCs;
12
use PhpGitHooks\Module\Configuration\Domain\PhpCsFixer;
13
use PhpGitHooks\Module\Configuration\Domain\PhpMd;
14
use PhpGitHooks\Module\Configuration\Domain\PhpUnit;
15
use PhpGitHooks\Module\Configuration\Domain\PhpUnitGuardCoverage;
16
use PhpGitHooks\Module\Configuration\Domain\PhpUnitStrictCoverage;
17
use PhpGitHooks\Module\Configuration\Domain\PreCommit;
18
use PhpGitHooks\Module\Configuration\Model\ConfigurationFileReaderInterface;
19
use PhpGitHooks\Module\Configuration\Service\ConfigurationDataResponseFactory;
20
21
class ConfigurationDataFinderHandler implements QueryHandlerInterface
22
{
23
    /**
24
     * @var ConfigurationFileReaderInterface
25
     */
26
    private $configurationFileReader;
27
28
    /**
29
     * ConfigurationDataFinder constructor.
30
     *
31
     * @param ConfigurationFileReaderInterface $configurationFileReader
32
     */
33 1
    public function __construct(ConfigurationFileReaderInterface $configurationFileReader)
34
    {
35 1
        $this->configurationFileReader = $configurationFileReader;
36 1
    }
37
38 1
    private function getConfigurationDataResponse(Config $data)
39
    {
40
        /** @var PreCommit $preCommit */
41 1
        $preCommit = $data->getPreCommit();
42
        /** @var CommitMsg $commitMsg */
43 1
        $commitMsg = $data->getCommitMsg();
44 1
        $tools = $preCommit->getExecute()->execute();
45
        /** @var PrePush $prePush */
46 1
        $prePush = $data->getPrePush();
47 1
        $prePushTools = $prePush->getExecute()->execute();
0 ignored issues
show
Bug introduced by
The method getExecute() does not seem to exist on object<PhpGitHooks\Infrastructure\Hook\PrePush>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
48
49 1
        $composer = $tools[0];
50 1
        $jsonLint = $tools[1];
51 1
        $phpLint = $tools[2];
52
        /** @var PhpMd $phpMd */
53 1
        $phpMd = $tools[3];
54
        /** @var PhpCs $phpCs */
55 1
        $phpCs = $tools[4];
56
        /** @var PhpCsFixer $phpCsFixer */
57 1
        $phpCsFixer = $tools[5];
58
        /** @var PhpUnit $phpUnit */
59 1
        $phpUnit = $tools[6];
60
        /** @var PhpUnitStrictCoverage $phpUnitStrictCoverage */
61 1
        $phpUnitStrictCoverage = $tools[7];
62
        /** @var PhpUnitGuardCoverage $phpUnitGuardCoverage */
63 1
        $phpUnitGuardCoverage = $tools[8];
64
        /** @var PhpUnit $prePushPhpUnit */
65 1
        $prePushPhpUnit = $prePushTools[0];
66
        /** @var PhpUnitStrictCoverage $prePushStrictCoverage */
67 1
        $prePushStrictCoverage = $prePushTools[1];
68
        /** @var PhpUnitGuardCoverage $prePushGuardCoverage */
69 1
        $prePushGuardCoverage = $prePushTools[2];
70
71 1
        return ConfigurationDataResponseFactory::build(
72
            $preCommit,
73
            $composer,
0 ignored issues
show
Compatibility introduced by
$composer of type object<PhpGitHooks\Modul...on\Model\ToolInterface> is not a sub-type of object<PhpGitHooks\Modul...ration\Domain\Composer>. 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...
74
            $jsonLint,
0 ignored issues
show
Compatibility introduced by
$jsonLint of type object<PhpGitHooks\Modul...on\Model\ToolInterface> is not a sub-type of object<PhpGitHooks\Modul...ration\Domain\JsonLint>. 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...
75
            $phpLint,
0 ignored issues
show
Compatibility introduced by
$phpLint of type object<PhpGitHooks\Modul...on\Model\ToolInterface> is not a sub-type of object<PhpGitHooks\Modul...uration\Domain\PhpLint>. 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...
76
            $phpMd,
77
            $phpCs,
78
            $phpCsFixer,
79
            $phpUnit,
80
            $phpUnitStrictCoverage,
81
            $phpUnitGuardCoverage,
82
            $commitMsg,
83
            $prePush,
0 ignored issues
show
Documentation introduced by
$prePush is of type object<PhpGitHooks\Infrastructure\Hook\PrePush>, but the function expects a object<PhpGitHooks\Modul...uration\Domain\PrePush>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
84
            $prePushPhpUnit,
85
            $prePushStrictCoverage,
86 1
            $prePushGuardCoverage
87
        );
88
    }
89
90
    /**
91
     * @param QueryInterface $query
92
     *
93
     * @return ConfigurationDataResponse
94
     */
95 1
    public function handle(QueryInterface $query)
96
    {
97 1
        $data = $this->configurationFileReader->getData();
98
99 1
        return $this->getConfigurationDataResponse($data);
100
    }
101
}
102