Completed
Pull Request — master (#85)
by
unknown
02:27
created

ConfigurationDataResponseFactory::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 75
Code Lines 60

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 75
ccs 0
cts 72
cp 0
rs 9
c 0
b 0
f 0
cc 1
eloc 60
nc 1
nop 15
crap 2

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
    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
        $commitMsgResponse = new CommitMsgResponse(
67
            $commitMsg->isEnabled(),
68
            $commitMsg->getRegularExpression()->value()
69
        );
70
71
        $prePushResponse = new PrePushResponse(
72
            $prePush->isEnabled(),
73
            $prePush->getMessages()->getRightMessage(),
74
            $prePush->getMessages()->getErrorMessage(),
75
            new PhpUnitResponse(
76
                $prePushPhpUnit->isEnabled(),
77
                $prePushPhpUnit->getRandomMode()->value(),
78
                $prePushPhpUnit->getOptions()->value()
79
            ),
80
            new PhpUnitStrictCoverageResponse(
81
                $prePushStrictCoverage->isEnabled(),
82
                $prePushStrictCoverage->getMinimumStrictCoverage()->value()
83
            ),
84
            new PhpUnitGuardCoverageResponse(
85
                $prePushGuardCoverage->isEnabled(),
86
                $prePushGuardCoverage->getWarningMessage()->value()
87
            )
88
        );
89
90
        $preCommitResponse = new PreCommitResponse(
91
            $preCommit->isEnabled(),
92
            $preCommit->getMessages()->getRightMessage()->value(),
93
            $preCommit->getMessages()->getErrorMessage()->value(),
94
            $composer->isEnabled(),
95
            $jsonLint->isEnabled(),
96
            $phpLint->isEnabled(),
97
            new PhpMdResponse($phpMd->isEnabled(), $phpMd->getOptions()->value()),
98
            new PhpCsResponse($phpCs->isEnabled(), $phpCs->getStandard()->value(), $phpCs->getIgnore()->value()),
99
            new PhpCsFixerResponse(
100
                $phpCsFixer->isEnabled(),
101
                $phpCsFixer->getLevels()->getPsr0()->value(),
102
                $phpCsFixer->getLevels()->getPsr1()->value(),
103
                $phpCsFixer->getLevels()->getPsr2()->value(),
104
                $phpCsFixer->getLevels()->getSymfony()->value(),
105
                $phpCsFixer->getOptions()->value()
106
            ),
107
            new PhpUnitResponse(
108
                $phpUnit->isEnabled(),
109
                $phpUnit->getRandomMode()->value(),
110
                $phpUnit->getOptions()->value()
111
            ),
112
            new PhpUnitStrictCoverageResponse(
113
                $phpUnitStrictCoverage->isEnabled(),
114
                $phpUnitStrictCoverage->getMinimumStrictCoverage()->value()
115
            ),
116
            new PhpUnitGuardCoverageResponse(
117
                $phpUnitGuardCoverage->isEnabled(),
118
                $phpUnitGuardCoverage->getWarningMessage()->value()
119
            )
120
        );
121
122
        return new ConfigurationDataResponse($preCommitResponse, $commitMsgResponse, $prePushResponse);
123
    }
124
}
125