Completed
Branch module_structure (3116d9)
by Pablo
02:56
created

ConfigurationDataResponseStub::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 55
Code Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 55
rs 9.7692
cc 1
eloc 52
nc 1
nop 25

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\Tests\Stub;
4
5
use PhpGitHooks\Module\Configuration\Contract\Response\ConfigurationDataResponse;
6
use PhpGitHooks\Module\Configuration\Service\HookQuestions;
7
8
final class ConfigurationDataResponseStub
9
{
10
    const PHPCS_STANDARD = 'PSR2';
11
    const FIX_YOUR_CODE = 'Fix your code';
12
    const GOOD_JOB = 'Good job';
13
14
    /**
15
     * @param bool        $preCommit
16
     * @param string|null $rightMessage
17
     * @param string|null $errorMessage
18
     * @param bool        $composer
19
     * @param bool        $jsonLint
20
     * @param bool        $phpLint
21
     * @param bool        $phpMd
22
     * @param bool        $phpCs
23
     * @param string|null $phpCsStandard
24
     * @param bool        $phpCsFixer
25
     * @param bool        $phpCsFixerPsr0
26
     * @param bool        $phpCsFixerPsr1
27
     * @param bool        $phpCsFixerPsr2
28
     * @param bool        $phpCsFixerSymfony
29
     * @param bool        $phpunit
30
     * @param bool        $phpunitRandomMode
31
     * @param string|null $phpunitOptions
32
     * @param bool        $commitMsg
33
     * @param string|null $regularExpression
34
     * @param bool        $prePush
35
     * @param bool        $prePushPhpUnit
36
     * @param bool        $prePushPhpUnitRandom
37
     * @param string|null $prePushPhpUnitOptions
38
     * @param string      $prePushRightMessage
39
     * @param string      $prePushErrorMessage
40
     *
41
     * @return ConfigurationDataResponse
42
     */
43
    public static function create(
44
        $preCommit,
45
        $rightMessage,
46
        $errorMessage,
47
        $composer,
48
        $jsonLint,
49
        $phpLint,
50
        $phpMd,
51
        $phpCs,
52
        $phpCsStandard,
53
        $phpCsFixer,
54
        $phpCsFixerPsr0,
55
        $phpCsFixerPsr1,
56
        $phpCsFixerPsr2,
57
        $phpCsFixerSymfony,
58
        $phpunit,
59
        $phpunitRandomMode,
60
        $phpunitOptions,
61
        $commitMsg,
62
        $regularExpression,
63
        $prePush,
64
        $prePushPhpUnit,
65
        $prePushPhpUnitRandom,
66
        $prePushPhpUnitOptions,
67
        $prePushRightMessage,
68
        $prePushErrorMessage
69
    ) {
70
        return new ConfigurationDataResponse(
71
            $preCommit,
72
            $rightMessage,
73
            $errorMessage,
74
            $composer,
75
            $jsonLint,
76
            $phpLint,
77
            $phpMd,
78
            $phpCs,
79
            $phpCsStandard,
80
            $phpCsFixer,
81
            $phpCsFixerPsr0,
82
            $phpCsFixerPsr1,
83
            $phpCsFixerPsr2,
84
            $phpCsFixerSymfony,
85
            $phpunit,
86
            $phpunitRandomMode,
87
            $phpunitOptions,
88
            $commitMsg,
89
            $regularExpression,
90
            $prePush,
91
            $prePushPhpUnit,
92
            $prePushPhpUnitRandom,
93
            $prePushPhpUnitOptions,
94
            $prePushRightMessage,
95
            $prePushErrorMessage
96
        );
97
    }
98
99
    /**
100
     * @return ConfigurationDataResponse
101
     */
102
    public static function createAllEnabled()
103
    {
104
        $bool = true;
105
106
        return static::create(
107
            $bool,
108
            static::GOOD_JOB,
109
            static::FIX_YOUR_CODE,
110
            $bool,
111
            $bool,
112
            $bool,
113
            $bool,
114
            $bool,
115
            static::PHPCS_STANDARD,
116
            $bool,
117
            $bool,
118
            $bool,
119
            $bool,
120
            $bool,
121
            $bool,
122
            $bool,
123
            null,
124
            $bool,
125
            null,
126
            $bool,
127
            $bool,
128
            $bool,
129
            null,
130
            static::GOOD_JOB,
131
            static::FIX_YOUR_CODE
132
        );
133
    }
134
135
    /**
136
     * @param bool $preCommit
137
     * @param bool $commitMsg
138
     * @param bool $prePush
139
     *
140
     * @return ConfigurationDataResponse
141
     */
142
    public static function createCustom($preCommit, $commitMsg, $prePush)
143
    {
144
        return static::create(
145
            $preCommit,
146
            static::GOOD_JOB,
147
            static::FIX_YOUR_CODE,
148
            $preCommit,
149
            $preCommit,
150
            $preCommit,
151
            $preCommit,
152
            $preCommit,
153
            static::PHPCS_STANDARD,
154
            $preCommit,
155
            $preCommit,
156
            $preCommit,
157
            $preCommit,
158
            $preCommit,
159
            $preCommit,
160
            $preCommit,
161
            null,
162
            $commitMsg,
163
            HookQuestions::COMMIT_MSG_REGULAR_EXPRESSION_ANSWER,
164
            $prePush,
165
            $prePush,
166
            $prePush,
167
            null,
168
            null,
169
            null
170
        );
171
    }
172
}
173