Conditions | 1 |
Paths | 1 |
Total Lines | 99 |
Code Lines | 54 |
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 |
||
131 | public function dataValidationFailed(): array |
||
132 | { |
||
133 | $defaultErrors = ['' => ['Value must be either "1" or "0".']]; |
||
134 | $booleanErrors = ['' => ['Value must be either "true" or "false".']]; |
||
135 | |||
136 | return [ |
||
137 | ['5', [new BooleanValue()], $defaultErrors], |
||
138 | |||
139 | [null, [new BooleanValue()], ['' => ['The allowed types are integer, float, string, boolean. null given.']]], |
||
140 | [[], [new BooleanValue()], ['' => ['The allowed types are integer, float, string, boolean. array given.']]], |
||
141 | |||
142 | [true, [new BooleanValue(strict: true)], $defaultErrors], |
||
143 | [false, [new BooleanValue(strict: true)], $defaultErrors], |
||
144 | |||
145 | ['0', [new BooleanValue(trueValue: true, falseValue: false, strict: true)], $booleanErrors], |
||
146 | [ |
||
147 | [], |
||
148 | [new BooleanValue(trueValue: true, falseValue: false, strict: true)], |
||
149 | ['' => ['The allowed types are integer, float, string, boolean. array given.']], |
||
150 | ], |
||
151 | |||
152 | 'custom message' => [ |
||
153 | 5, |
||
154 | [new BooleanValue(message: 'Custom error.')], |
||
155 | ['' => ['Custom error.']], |
||
156 | ], |
||
157 | 'custom message with parameters' => [ |
||
158 | 5, |
||
159 | [ |
||
160 | new BooleanValue( |
||
161 | message: 'Attribute - {attribute}, true - {true}, false - {false}, value - {value}.', |
||
162 | ), |
||
163 | ], |
||
164 | ['' => ['Attribute - , true - 1, false - 0, value - 5.']], |
||
165 | ], |
||
166 | 'custom message with parameters, custom true and false values, strict' => [ |
||
167 | 5, |
||
168 | [ |
||
169 | new BooleanValue( |
||
170 | trueValue: true, |
||
171 | falseValue: false, |
||
172 | strict: true, |
||
173 | message: 'Attribute - {attribute}, true - {true}, false - {false}, value - {value}.', |
||
174 | ), |
||
175 | ], |
||
176 | ['' => ['Attribute - , true - true, false - false, value - 5.']], |
||
177 | ], |
||
178 | 'custom message with parameters, attribute set' => [ |
||
179 | ['data' => 5], |
||
180 | [ |
||
181 | 'data' => new BooleanValue( |
||
182 | message: 'Attribute - {attribute}, true - {true}, false - {false}, value - {value}.', |
||
183 | ), |
||
184 | ], |
||
185 | ['data' => ['Attribute - data, true - 1, false - 0, value - 5.']], |
||
186 | ], |
||
187 | 'custom incorrect input message' => [ |
||
188 | [], |
||
189 | [new BooleanValue(incorrectInputMessage: 'Custom error.')], |
||
190 | ['' => ['Custom error.']], |
||
191 | ], |
||
192 | 'custom incorrect input message with parameters' => [ |
||
193 | [], |
||
194 | [ |
||
195 | new BooleanValue( |
||
196 | incorrectInputMessage: 'Attribute - {attribute}, true - {true}, false - {false}, type - {type}.', |
||
197 | ), |
||
198 | ], |
||
199 | ['' => ['Attribute - , true - 1, false - 0, type - array.']], |
||
200 | ], |
||
201 | 'custom incorrect input message with parameters, custom true and false values, strict' => [ |
||
202 | [], |
||
203 | [ |
||
204 | new BooleanValue( |
||
205 | trueValue: true, |
||
206 | falseValue: false, |
||
207 | strict: true, |
||
208 | incorrectInputMessage: 'Attribute - {attribute}, true - {true}, false - {false}, type - {type}.', |
||
209 | ), |
||
210 | ], |
||
211 | ['' => ['Attribute - , true - true, false - false, type - array.']], |
||
212 | ], |
||
213 | 'custom incorrect input message with parameters, attribute set' => [ |
||
214 | ['data' => []], |
||
215 | [ |
||
216 | 'data' => new BooleanValue( |
||
217 | incorrectInputMessage: 'Attribute - {attribute}, true - {true}, false - {false}, type - {type}.', |
||
218 | ), |
||
219 | ], |
||
220 | ['data' => ['Attribute - data, true - 1, false - 0, type - array.']], |
||
221 | ], |
||
222 | 'custom incorrect input message, null' => [ |
||
223 | null, |
||
224 | [ |
||
225 | new BooleanValue( |
||
226 | incorrectInputMessage: 'Attribute - {attribute}, true - {true}, false - {false}, type - {type}.', |
||
227 | ), |
||
228 | ], |
||
229 | ['' => ['Attribute - , true - 1, false - 0, type - null.']], |
||
230 | ], |
||
250 |