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