ConfigurationDataResponseFactory::build()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 75

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 45
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 75
rs 8.5454
c 0
b 0
f 0
ccs 45
cts 45
cp 1
cc 1
nc 1
nop 15
crap 1

How to fix   Long Method    Many Parameters   

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:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace PhpGitHooks\Module\Configuration\Service;
4
5
use PhpGitHooks\Module\Configuration\Contract\Response\CommitMsgResponse;
6
use PhpGitHooks\Module\Configuration\Contract\Response\ConfigurationDataResponse;
7
use PhpGitHooks\Module\Configuration\Contract\Response\PhpCsFixerResponse;
8
use PhpGitHooks\Module\Configuration\Contract\Response\PhpCsResponse;
9
use PhpGitHooks\Module\Configuration\Contract\Response\PhpUnitGuardCoverageResponse;
10
use PhpGitHooks\Module\Configuration\Contract\Response\PhpUnitResponse;
11
use PhpGitHooks\Module\Configuration\Contract\Response\PhpUnitStrictCoverageResponse;
12
use PhpGitHooks\Module\Configuration\Contract\Response\PhpMdResponse;
13
use PhpGitHooks\Module\Configuration\Contract\Response\PreCommitResponse;
14
use PhpGitHooks\Module\Configuration\Contract\Response\PrePushResponse;
15
use PhpGitHooks\Module\Configuration\Domain\CommitMsg;
16
use PhpGitHooks\Module\Configuration\Domain\Composer;
17
use PhpGitHooks\Module\Configuration\Domain\JsonLint;
18
use PhpGitHooks\Module\Configuration\Domain\PhpCs;
19
use PhpGitHooks\Module\Configuration\Domain\PhpCsFixer;
20
use PhpGitHooks\Module\Configuration\Domain\PhpLint;
21
use PhpGitHooks\Module\Configuration\Domain\PhpMd;
22
use PhpGitHooks\Module\Configuration\Domain\PhpUnit;
23
use PhpGitHooks\Module\Configuration\Domain\PhpUnitGuardCoverage;
24
use PhpGitHooks\Module\Configuration\Domain\PhpUnitStrictCoverage;
25
use PhpGitHooks\Module\Configuration\Domain\PreCommit;
26
use PhpGitHooks\Module\Configuration\Domain\PrePush;
27
28
class ConfigurationDataResponseFactory
29
{
30
    /**
31
     * @param PreCommit             $preCommit
32
     * @param Composer              $composer
33
     * @param JsonLint              $jsonLint
34
     * @param PhpLint               $phpLint
35
     * @param PhpMd                 $phpMd
36
     * @param PhpCs                 $phpCs
37
     * @param PhpCsFixer            $phpCsFixer
38
     * @param PhpUnit               $phpUnit
39
     * @param PhpUnitStrictCoverage $phpUnitStrictCoverage
40
     * @param PhpUnitGuardCoverage  $phpUnitGuardCoverage
41
     * @param CommitMsg             $commitMsg
42
     * @param PrePush               $prePush
43
     * @param PhpUnit               $prePushPhpUnit
44
     * @param PhpUnitStrictCoverage $prePushStrictCoverage
45
     * @param PhpUnitGuardCoverage  $prePushGuardCoverage
46
     *
47
     * @return ConfigurationDataResponse
48
     */
49 1
    public static function build(
50
        PreCommit $preCommit,
51
        Composer $composer,
52
        JsonLint $jsonLint,
53
        PhpLint $phpLint,
54
        PhpMd $phpMd,
55
        PhpCs $phpCs,
56
        PhpCsFixer $phpCsFixer,
57
        PhpUnit $phpUnit,
58
        PhpUnitStrictCoverage $phpUnitStrictCoverage,
59
        PhpUnitGuardCoverage $phpUnitGuardCoverage,
60
        CommitMsg $commitMsg,
61
        PrePush $prePush,
62
        PhpUnit $prePushPhpUnit,
63
        PhpUnitStrictCoverage $prePushStrictCoverage,
64
        PhpUnitGuardCoverage $prePushGuardCoverage
65
    ) {
66 1
        $commitMsgResponse = new CommitMsgResponse(
67 1
            $commitMsg->isEnabled(),
68 1
            $commitMsg->getRegularExpression()->value()
69
        );
70
71 1
        $prePushResponse = new PrePushResponse(
72 1
            $prePush->isEnabled(),
73 1
            $prePush->getMessages()->getRightMessage(),
74 1
            $prePush->getMessages()->getErrorMessage(),
75 1
            new PhpUnitResponse(
76 1
                $prePushPhpUnit->isEnabled(),
77 1
                $prePushPhpUnit->getRandomMode()->value(),
78 1
                $prePushPhpUnit->getOptions()->value()
79
            ),
80 1
            new PhpUnitStrictCoverageResponse(
81 1
                $prePushStrictCoverage->isEnabled(),
82 1
                $prePushStrictCoverage->getMinimumStrictCoverage()->value()
83
            ),
84 1
            new PhpUnitGuardCoverageResponse(
85 1
                $prePushGuardCoverage->isEnabled(),
86 1
                $prePushGuardCoverage->getWarningMessage()->value()
87
            )
88
        );
89
90 1
        $preCommitResponse = new PreCommitResponse(
91 1
            $preCommit->isEnabled(),
92 1
            $preCommit->getMessages()->getRightMessage()->value(),
93 1
            $preCommit->getMessages()->getErrorMessage()->value(),
94 1
            $composer->isEnabled(),
95 1
            $jsonLint->isEnabled(),
96 1
            $phpLint->isEnabled(),
97 1
            new PhpMdResponse($phpMd->isEnabled(), $phpMd->getOptions()->value()),
98 1
            new PhpCsResponse($phpCs->isEnabled(), $phpCs->getStandard()->value(), $phpCs->getIgnore()->value()),
99 1
            new PhpCsFixerResponse(
100 1
                $phpCsFixer->isEnabled(),
101 1
                $phpCsFixer->getLevels()->getPsr0()->value(),
102 1
                $phpCsFixer->getLevels()->getPsr1()->value(),
103 1
                $phpCsFixer->getLevels()->getPsr2()->value(),
104 1
                $phpCsFixer->getLevels()->getSymfony()->value(),
105 1
                $phpCsFixer->getOptions()->value()
106
            ),
107 1
            new PhpUnitResponse(
108 1
                $phpUnit->isEnabled(),
109 1
                $phpUnit->getRandomMode()->value(),
110 1
                $phpUnit->getOptions()->value()
111
            ),
112 1
            new PhpUnitStrictCoverageResponse(
113 1
                $phpUnitStrictCoverage->isEnabled(),
114 1
                $phpUnitStrictCoverage->getMinimumStrictCoverage()->value()
115
            ),
116 1
            new PhpUnitGuardCoverageResponse(
117 1
                $phpUnitGuardCoverage->isEnabled(),
118 1
                $phpUnitGuardCoverage->getWarningMessage()->value()
119
            )
120
        );
121
122 1
        return new ConfigurationDataResponse($preCommitResponse, $commitMsgResponse, $prePushResponse);
123
    }
124
}
125