Conditions | 1 |
Paths | 1 |
Total Lines | 141 |
Code Lines | 101 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
29 | public function dataOptions(): array |
||
30 | { |
||
31 | return [ |
||
32 | [ |
||
33 | new Number(), |
||
34 | [ |
||
35 | 'asInteger' => false, |
||
36 | 'min' => null, |
||
37 | 'max' => null, |
||
38 | 'incorrectInputMessage' => [ |
||
39 | 'template' => 'The allowed types are integer, float and string.', |
||
40 | 'parameters' => [], |
||
41 | ], |
||
42 | 'notNumberMessage' => [ |
||
43 | 'template' => 'Value must be a number.', |
||
44 | 'parameters' => [], |
||
45 | ], |
||
46 | 'tooSmallMessage' => [ |
||
47 | 'template' => 'Value must be no less than {min}.', |
||
48 | 'parameters' => ['min' => null], |
||
49 | ], |
||
50 | 'tooBigMessage' => [ |
||
51 | 'template' => 'Value must be no greater than {max}.', |
||
52 | 'parameters' => ['max' => null], |
||
53 | ], |
||
54 | 'skipOnEmpty' => false, |
||
55 | 'skipOnError' => false, |
||
56 | 'integerPattern' => '/^\s*[+-]?\d+\s*$/', |
||
57 | 'numberPattern' => '/^\s*[-+]?\d*\.?\d+([eE][-+]?\d+)?\s*$/', |
||
58 | ], |
||
59 | ], |
||
60 | [ |
||
61 | new Number(min: 1), |
||
62 | [ |
||
63 | 'asInteger' => false, |
||
64 | 'min' => 1, |
||
65 | 'max' => null, |
||
66 | 'incorrectInputMessage' => [ |
||
67 | 'template' => 'The allowed types are integer, float and string.', |
||
68 | 'parameters' => [], |
||
69 | ], |
||
70 | 'notNumberMessage' => [ |
||
71 | 'template' => 'Value must be a number.', |
||
72 | 'parameters' => [], |
||
73 | ], |
||
74 | 'tooSmallMessage' => [ |
||
75 | 'template' => 'Value must be no less than {min}.', |
||
76 | 'parameters' => ['min' => 1], |
||
77 | ], |
||
78 | 'tooBigMessage' => [ |
||
79 | 'template' => 'Value must be no greater than {max}.', |
||
80 | 'parameters' => ['max' => null], |
||
81 | ], |
||
82 | 'skipOnEmpty' => false, |
||
83 | 'skipOnError' => false, |
||
84 | 'integerPattern' => '/^\s*[+-]?\d+\s*$/', |
||
85 | 'numberPattern' => '/^\s*[-+]?\d*\.?\d+([eE][-+]?\d+)?\s*$/', |
||
86 | ], |
||
87 | ], |
||
88 | [ |
||
89 | new Number(max: 1), |
||
90 | [ |
||
91 | 'asInteger' => false, |
||
92 | 'min' => null, |
||
93 | 'max' => 1, |
||
94 | 'incorrectInputMessage' => [ |
||
95 | 'template' => 'The allowed types are integer, float and string.', |
||
96 | 'parameters' => [], |
||
97 | ], |
||
98 | 'notNumberMessage' => [ |
||
99 | 'template' => 'Value must be a number.', |
||
100 | 'parameters' => [], |
||
101 | ], |
||
102 | 'tooSmallMessage' => [ |
||
103 | 'template' => 'Value must be no less than {min}.', |
||
104 | 'parameters' => ['min' => null], |
||
105 | ], |
||
106 | 'tooBigMessage' => [ |
||
107 | 'template' => 'Value must be no greater than {max}.', |
||
108 | 'parameters' => ['max' => 1], |
||
109 | ], |
||
110 | 'skipOnEmpty' => false, |
||
111 | 'skipOnError' => false, |
||
112 | 'integerPattern' => '/^\s*[+-]?\d+\s*$/', |
||
113 | 'numberPattern' => '/^\s*[-+]?\d*\.?\d+([eE][-+]?\d+)?\s*$/', |
||
114 | ], |
||
115 | ], |
||
116 | [ |
||
117 | new Number(min: 2, max: 10), |
||
118 | [ |
||
119 | 'asInteger' => false, |
||
120 | 'min' => 2, |
||
121 | 'max' => 10, |
||
122 | 'incorrectInputMessage' => [ |
||
123 | 'template' => 'The allowed types are integer, float and string.', |
||
124 | 'parameters' => [], |
||
125 | ], |
||
126 | 'notNumberMessage' => [ |
||
127 | 'template' => 'Value must be a number.', |
||
128 | 'parameters' => [], |
||
129 | ], |
||
130 | 'tooSmallMessage' => [ |
||
131 | 'template' => 'Value must be no less than {min}.', |
||
132 | 'parameters' => ['min' => 2], |
||
133 | ], |
||
134 | 'tooBigMessage' => [ |
||
135 | 'template' => 'Value must be no greater than {max}.', |
||
136 | 'parameters' => ['max' => 10], |
||
137 | ], |
||
138 | 'skipOnEmpty' => false, |
||
139 | 'skipOnError' => false, |
||
140 | 'integerPattern' => '/^\s*[+-]?\d+\s*$/', |
||
141 | 'numberPattern' => '/^\s*[-+]?\d*\.?\d+([eE][-+]?\d+)?\s*$/', |
||
142 | ], |
||
143 | ], |
||
144 | [ |
||
145 | new Number(asInteger: true), |
||
146 | [ |
||
147 | 'asInteger' => true, |
||
148 | 'min' => null, |
||
149 | 'max' => null, |
||
150 | 'incorrectInputMessage' => [ |
||
151 | 'template' => 'The allowed types are integer, float and string.', |
||
152 | 'parameters' => [], |
||
153 | ], |
||
154 | 'notNumberMessage' => [ |
||
155 | 'template' => 'Value must be an integer.', |
||
156 | 'parameters' => [], |
||
157 | ], |
||
158 | 'tooSmallMessage' => [ |
||
159 | 'template' => 'Value must be no less than {min}.', |
||
160 | 'parameters' => ['min' => null], |
||
161 | ], |
||
162 | 'tooBigMessage' => [ |
||
163 | 'template' => 'Value must be no greater than {max}.', |
||
164 | 'parameters' => ['max' => null], |
||
165 | ], |
||
166 | 'skipOnEmpty' => false, |
||
167 | 'skipOnError' => false, |
||
168 | 'integerPattern' => '/^\s*[+-]?\d+\s*$/', |
||
169 | 'numberPattern' => '/^\s*[-+]?\d*\.?\d+([eE][-+]?\d+)?\s*$/', |
||
170 | ], |
||
287 |