Completed
Push — master ( 30874d...ed8031 )
by Pablo
02:56
created

ConfigurationDataResponseFactory::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 64
Code Lines 51

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 46
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 64
ccs 46
cts 46
cp 1
rs 9.3956
cc 1
eloc 51
nc 1
nop 13
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\PhpUnitResponse;
10
use PhpGitHooks\Module\Configuration\Contract\Response\PhpUnitStrictCoverageResponse;
11
use PhpGitHooks\Module\Configuration\Contract\Response\PhpMdResponse;
12
use PhpGitHooks\Module\Configuration\Contract\Response\PreCommitResponse;
13
use PhpGitHooks\Module\Configuration\Contract\Response\PrePushResponse;
14
use PhpGitHooks\Module\Configuration\Domain\CommitMsg;
15
use PhpGitHooks\Module\Configuration\Domain\Composer;
16
use PhpGitHooks\Module\Configuration\Domain\JsonLint;
17
use PhpGitHooks\Module\Configuration\Domain\PhpCs;
18
use PhpGitHooks\Module\Configuration\Domain\PhpCsFixer;
19
use PhpGitHooks\Module\Configuration\Domain\PhpLint;
20
use PhpGitHooks\Module\Configuration\Domain\PhpMd;
21
use PhpGitHooks\Module\Configuration\Domain\PhpUnit;
22
use PhpGitHooks\Module\Configuration\Domain\PhpUnitStrictCoverage;
23
use PhpGitHooks\Module\Configuration\Domain\PreCommit;
24
use PhpGitHooks\Module\Configuration\Domain\PrePush;
25
26
class ConfigurationDataResponseFactory
27
{
28 1
    public static function build(
29
        PreCommit $preCommit,
30
        Composer $composer,
31
        JsonLint $jsonLint,
32
        PhpLint $phpLint,
33
        PhpMd $phpMd,
34
        PhpCs $phpCs,
35
        PhpCsFixer $phpCsFixer,
36
        PhpUnit $phpUnit,
37
        PhpUnitStrictCoverage $phpUnitStrictCoverage,
38
        CommitMsg $commitMsg,
39
        PrePush $prePush,
40
        PhpUnit $prePushPhpUnit,
41
        PhpUnitStrictCoverage $prePushStrictCoverage
42
    ) {
43 1
        $commitMsgResponse = new CommitMsgResponse(
44 1
            $commitMsg->isEnabled(),
45 1
            $commitMsg->getRegularExpression()->value()
46 1
        );
47
48 1
        $prePushResponse = new PrePushResponse(
49 1
            $prePush->isEnabled(),
50 1
            $prePush->getMessages()->getRightMessage(),
51 1
            $prePush->getMessages()->getErrorMessage(),
52 1
            new PhpUnitResponse(
53 1
                $prePushPhpUnit->isEnabled(),
54 1
                $prePushPhpUnit->getRandomMode()->value(),
55 1
                $prePushPhpUnit->getOptions()->value()
56 1
            ),
57 1
            new PhpUnitStrictCoverageResponse(
58 1
                $prePushStrictCoverage->isEnabled(),
59 1
                $prePushStrictCoverage->getMinimumStrictCoverage()->value()
60 1
            )
61 1
        );
62
63 1
        $preCommitResponse = new PreCommitResponse(
64 1
            $preCommit->isEnabled(),
65 1
            $preCommit->getMessages()->getRightMessage()->value(),
66 1
            $preCommit->getMessages()->getErrorMessage()->value(),
67 1
            $composer->isEnabled(),
68 1
            $jsonLint->isEnabled(),
69 1
            $phpLint->isEnabled(),
70 1
            new PhpMdResponse($phpMd->isEnabled(), $phpMd->getOptions()->value()),
71 1
            new PhpCsResponse($phpCs->isEnabled(), $phpCs->getStandard()->value()),
72 1
            new PhpCsFixerResponse(
73 1
                $phpCsFixer->isEnabled(),
74 1
                $phpCsFixer->getLevels()->getPsr0()->value(),
75 1
                $phpCsFixer->getLevels()->getPsr1()->value(),
76 1
                $phpCsFixer->getLevels()->getPsr2()->value(),
77 1
                $phpCsFixer->getLevels()->getSymfony()->value()
78 1
            ),
79 1
            new PhpUnitResponse(
80 1
                $phpUnit->isEnabled(),
81 1
                $phpUnit->getRandomMode()->value(),
82 1
                $phpUnit->getOptions()->value()
83 1
            ),
84 1
            new PhpUnitStrictCoverageResponse(
85 1
                $phpUnitStrictCoverage->isEnabled(),
86 1
                $phpUnitStrictCoverage->getMinimumStrictCoverage()->value()
87 1
            )
88 1
        );
89
90 1
        return new ConfigurationDataResponse($preCommitResponse, $commitMsgResponse, $prePushResponse);
91
    }
92
}
93