Conditions | 1 |
Paths | 1 |
Total Lines | 107 |
Code Lines | 62 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
170 | public function dataValidationFailed(): array |
||
171 | { |
||
172 | $getGeneratorWithIncorrectKey = static function (): Generator { |
||
173 | yield false => 0; |
||
174 | }; |
||
175 | |||
176 | return [ |
||
177 | 'incorrect input' => [1, [new Each([new Number(max: 13)])], ['' => ['Value must be array or iterable.']]], |
||
178 | 'custom incorrect input message' => [ |
||
179 | 1, |
||
180 | [new Each([new Number(max: 13)], incorrectInputMessage: 'Custom incorrect input message.')], |
||
181 | ['' => ['Custom incorrect input message.']], |
||
182 | ], |
||
183 | 'custom incorrect input message with parameters' => [ |
||
184 | 1, |
||
185 | [new Each([new Number(max: 13)], incorrectInputMessage: 'Attribute - {attribute}, type - {type}.')], |
||
186 | ['' => ['Attribute - , type - int.']], |
||
187 | ], |
||
188 | 'custom incorrect input message with parameters, attribute set' => [ |
||
189 | ['data' => 1], |
||
190 | [ |
||
191 | 'data' => new Each( |
||
192 | [new Number(max: 13)], |
||
193 | incorrectInputMessage: 'Attribute - {attribute}, type - {type}.', |
||
194 | ), |
||
195 | ], |
||
196 | ['data' => ['Attribute - data, type - int.']], |
||
197 | ], |
||
198 | |||
199 | 'incorrect input key' => [ |
||
200 | ['attribute' => $getGeneratorWithIncorrectKey()], |
||
201 | ['attribute' => new Each([new Number(max: 13)])], |
||
202 | ['attribute' => ['Every iterable key must have an integer or a string type.']], |
||
203 | ], |
||
204 | 'custom incorrect input key message' => [ |
||
205 | ['attribute' => $getGeneratorWithIncorrectKey()], |
||
206 | [ |
||
207 | 'attribute' => new Each( |
||
208 | [new Number(max: 13)], |
||
209 | incorrectInputKeyMessage: 'Custom incorrect input key message.', |
||
210 | ), |
||
211 | ], |
||
212 | ['attribute' => ['Custom incorrect input key message.']], |
||
213 | ], |
||
214 | 'custom incorrect input key message with parameters' => [ |
||
215 | ['attribute' => $getGeneratorWithIncorrectKey()], |
||
216 | [ |
||
217 | 'attribute' => new Each( |
||
218 | [new Number(max: 13)], |
||
219 | incorrectInputKeyMessage: 'Attribute - {attribute}, type - {type}.', |
||
220 | ), |
||
221 | ], |
||
222 | ['attribute' => ['Attribute - attribute, type - Generator.']], |
||
223 | ], |
||
224 | |||
225 | [ |
||
226 | [10, 20, 30], |
||
227 | [new Each([new Number(max: 13)])], |
||
228 | [ |
||
229 | '1' => ['Value must be no greater than 13.'], |
||
230 | '2' => ['Value must be no greater than 13.'], |
||
231 | ], |
||
232 | ], |
||
233 | |||
234 | 'single rule' => [ |
||
235 | [10, 20, 30], |
||
236 | [new Each(new Number(max: 13))], |
||
237 | [ |
||
238 | '1' => ['Value must be no greater than 13.'], |
||
239 | '2' => ['Value must be no greater than 13.'], |
||
240 | ], |
||
241 | ], |
||
242 | 'single callable rule' => [ |
||
243 | [10, 20], |
||
244 | [new Each(static fn (): Result => (new Result())->addError('error'))], |
||
245 | [ |
||
246 | 0 => ['error'], |
||
247 | 1 => ['error'], |
||
248 | ], |
||
249 | ], |
||
250 | 'rules array with callable' => [ |
||
251 | [10, 20], |
||
252 | [new Each([static fn (): Result => (new Result())->addError('error')])], |
||
253 | [ |
||
254 | 0 => ['error'], |
||
255 | 1 => ['error'], |
||
256 | ], |
||
257 | ], |
||
258 | |||
259 | 'custom message' => [ |
||
260 | [10, 20, 30], |
||
261 | [new Each([new Number(max: 13, greaterThanMaxMessage: 'Custom too big message.')])], |
||
262 | [ |
||
263 | '1' => ['Custom too big message.'], |
||
264 | '2' => ['Custom too big message.'], |
||
265 | ], |
||
266 | ], |
||
267 | 'custom message with parameters' => [ |
||
268 | [10, 20, 30], |
||
269 | [ |
||
270 | new Each( |
||
271 | [new Number(max: 13, greaterThanMaxMessage: 'Max - {max}, value - {value}.')], |
||
272 | ), |
||
273 | ], |
||
274 | [ |
||
275 | '1' => ['Max - 13, value - 20.'], |
||
276 | '2' => ['Max - 13, value - 30.'], |
||
277 | ], |
||
298 |