ConfigurationArrayTransformer::transform()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 100

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 51
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 100
rs 8
c 0
b 0
f 0
ccs 51
cts 51
cp 1
cc 1
nc 1
nop 3
crap 1

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\Service;
4
5
use PhpGitHooks\Module\Configuration\Domain\CommitMsg;
6
use PhpGitHooks\Module\Configuration\Domain\PhpCs;
7
use PhpGitHooks\Module\Configuration\Domain\PhpCsFixer;
8
use PhpGitHooks\Module\Configuration\Domain\PhpMd;
9
use PhpGitHooks\Module\Configuration\Domain\PhpUnit;
10
use PhpGitHooks\Module\Configuration\Domain\PhpUnitGuardCoverage;
11
use PhpGitHooks\Module\Configuration\Domain\PhpUnitStrictCoverage;
12
use PhpGitHooks\Module\Configuration\Domain\PreCommit;
13
use PhpGitHooks\Module\Configuration\Domain\PrePush;
14
15
class ConfigurationArrayTransformer
16
{
17
    /**
18
     * @param PreCommit $preCommit
19
     * @param CommitMsg $commitMsg
20
     * @param PrePush $prePush
21
     *
22
     * @return array
23
     */
24 2
    public static function transform(PreCommit $preCommit, CommitMsg $commitMsg, PrePush $prePush)
25
    {
26 2
        $tools = $preCommit->getExecute()->execute();
27 2
        $prePushTools = $prePush->getExecute()->execute();
28 2
        $composer = $tools[0];
29 2
        $jsonLint = $tools[1];
30 2
        $phpLint = $tools[2];
31
        /** @var PhpMd $phpMd */
32 2
        $phpMd = $tools[3];
33
        /** @var PhpCs $phpCs */
34 2
        $phpCs = $tools[4];
35
        /** @var PhpCsFixer $phpCsFixer */
36 2
        $phpCsFixer = $tools[5];
37
        /** @var PhpUnit $phpunit */
38 2
        $phpunit = $tools[6];
39
        /** @var PhpUnitStrictCoverage $phpUnitStrictCoverage */
40 2
        $phpUnitStrictCoverage = $tools[7];
41
        /** @var PhpUnitGuardCoverage $phpUnitGuardCoverage */
42 2
        $phpUnitGuardCoverage = $tools[8];
43
        
44
        /** @var PhpUnit $phpunitPrePush */
45 2
        $phpunitPrePush = $prePushTools[0];
46
        /** @var PhpUnitStrictCoverage $phpUnitStrictCoveragePrePush */
47 2
        $phpUnitStrictCoveragePrePush = $prePushTools[1];
48
        /** @var PhpUnitGuardCoverage $phpUnitGuardCoveragePrePush */
49 2
        $phpUnitGuardCoveragePrePush = $prePushTools[2];
50
51
        return [
52
            'pre-commit' => [
53 2
                'enabled' => $preCommit->isEnabled(),
54
                'execute' => [
55 2
                    'composer' => $composer->isEnabled(),
56 2
                    'jsonlint' => $jsonLint->isEnabled(),
57 2
                    'phplint' => $phpLint->isEnabled(),
58
                    'phpmd' => [
59 2
                        'enabled' => $phpMd->isEnabled(),
60 2
                        'options' => $phpMd->getOptions()->value(),
61
                    ],
62
                    'phpcs' => [
63 2
                        'enabled' => $phpCs->isEnabled(),
64 2
                        'standard' => $phpCs->getStandard()->value(),
65 2
                        'ignore' => $phpCs->getIgnore()->value(),
66
                    ],
67
                    'php-cs-fixer' => [
68 2
                        'enabled' => $phpCsFixer->isEnabled(),
69
                        'levels' => [
70 2
                            'psr0' => $phpCsFixer->getLevels()->getPsr0()->value(),
71 2
                            'psr1' => $phpCsFixer->getLevels()->getPsr1()->value(),
72 2
                            'psr2' => $phpCsFixer->getLevels()->getPsr2()->value(),
73 2
                            'symfony' => $phpCsFixer->getLevels()->getSymfony()->value(),
74
                        ],
75 2
                        'options' => $phpCsFixer->getOptions()->value(),
76
                    ],
77
                    'phpunit' => [
78 2
                        'enabled' => $phpunit->isEnabled(),
79 2
                        'random-mode' => $phpunit->getRandomMode()->value(),
80 2
                        'options' => $phpunit->getOptions()->value(),
81
                        'strict-coverage' => [
82 2
                            'enabled' => $phpUnitStrictCoverage->isEnabled(),
83 2
                            'minimum' => $phpUnitStrictCoverage->getMinimumStrictCoverage()->value(),
84
                        ],
85
                        'guard-coverage' => [
86 2
                            'enabled' => $phpUnitGuardCoverage->isEnabled(),
87 2
                            'message' => $phpUnitGuardCoverage->getWarningMessage()->value(),
88
                        ],
89
                    ],
90
                ],
91
                'message' => [
92 2
                    'right-message' => $preCommit->getMessages()->getRightMessage()->value(),
93 2
                    'error-message' => $preCommit->getMessages()->getErrorMessage()->value(),
94
                ],
95
            ],
96
            'commit-msg' => [
97 2
                'enabled' => $commitMsg->isEnabled(),
98 2
                'regular-expression' => $commitMsg->getRegularExpression()->value(),
99
            ],
100
            'pre-push' => [
101 2
                'enabled' => $prePush->isEnabled(),
102
                'execute' => [
103
                    'phpunit' => [
104 2
                        'enabled' => $phpunitPrePush->isEnabled(),
105 2
                        'random-mode' => $phpunitPrePush->getRandomMode()->value(),
106 2
                        'options' => $phpunitPrePush->getOptions()->value(),
107
                        'strict-coverage' => [
108 2
                            'enabled' => $phpUnitStrictCoveragePrePush->isEnabled(),
109 2
                            'minimum' => $phpUnitStrictCoveragePrePush->getMinimumStrictCoverage()->value(),
110
                        ],
111
                        'guard-coverage' => [
112 2
                            'enabled' => $phpUnitGuardCoveragePrePush->isEnabled(),
113 2
                            'message' => $phpUnitGuardCoveragePrePush->getWarningMessage()->value()
114
                        ],
115
                    ],
116
                ],
117
                'message' => [
118 2
                    'right-message' => $prePush->getMessages()->getRightMessage()->value(),
119 2
                    'error-message' => $prePush->getMessages()->getErrorMessage()->value(),
120
                ],
121
            ],
122
        ];
123
    }
124
}
125