Total Lines | 73 |
Code Lines | 52 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
185 | public function dataValidationFailed(): array |
||
186 | { |
||
187 | $class = new class () { |
||
188 | public $attr1 = 1; |
||
189 | public $attr2 = null; |
||
190 | }; |
||
191 | $array = ['attr1' => 1, 'attr2' => null]; |
||
192 | |||
193 | return [ |
||
194 | 'incorrect input' => [ |
||
195 | 1, |
||
196 | [new AtLeast(['attr2'])], |
||
197 | ['' => ['The value must be an array or an object.']], |
||
198 | ], |
||
199 | 'custom incorrect input message' => [ |
||
200 | 1, |
||
201 | [new AtLeast(['attr2'], incorrectInputMessage: 'Custom incorrect input message.')], |
||
202 | ['' => ['Custom incorrect input message.']], |
||
203 | ], |
||
204 | 'custom incorrect input message with parameters' => [ |
||
205 | 1, |
||
206 | [new AtLeast(['attr2'], incorrectInputMessage: 'Attribute - {attribute}, type - {type}.')], |
||
207 | ['' => ['Attribute - , type - int.']], |
||
208 | ], |
||
209 | 'custom incorrect input message with parameters, attribute set' => [ |
||
210 | ['attribute' => 1], |
||
211 | [ |
||
212 | 'attribute' => new AtLeast( |
||
213 | ['attr2'], |
||
214 | incorrectInputMessage: 'Attribute - {attribute}, type - {type}.', |
||
215 | ), |
||
216 | ], |
||
217 | ['attribute' => ['Attribute - attribute, type - int.']], |
||
218 | ], |
||
219 | 'object' => [ |
||
220 | $class, |
||
221 | [new AtLeast(['attr2'])], |
||
222 | ['' => ['At least 1 attribute from this list must be filled: "attr2".']], |
||
223 | ], |
||
224 | 'object, custom min' => [ |
||
225 | $class, |
||
226 | [new AtLeast(['attr1', 'attr2'], min: 2)], |
||
227 | ['' => ['At least 2 attributes from this list must be filled: "attr1", "attr2".']], |
||
228 | ], |
||
229 | 'array' => [ |
||
230 | $array, |
||
231 | [new AtLeast(['attr2'])], |
||
232 | ['' => ['At least 1 attribute from this list must be filled: "attr2".']], |
||
233 | ], |
||
234 | 'array, custom min' => [ |
||
235 | $array, |
||
236 | [new AtLeast(['attr1', 'attr2'], min: 2)], |
||
237 | ['' => ['At least 2 attributes from this list must be filled: "attr1", "attr2".']], |
||
238 | ], |
||
239 | 'custom message' => [ |
||
240 | $class, |
||
241 | [new AtLeast(['attr1', 'attr2'], min: 2, message: 'Custom message.')], |
||
242 | ['' => ['Custom message.']], |
||
243 | ], |
||
244 | 'custom message with parameters' => [ |
||
245 | $class, |
||
246 | [new AtLeast(['attr1', 'attr2'], min: 2, message: 'Attributes - {attributes}, min - {min}.')], |
||
247 | ['' => ['Attributes - "attr1", "attr2", min - 2.']], |
||
248 | ], |
||
249 | 'custom message with parameters, attribute set' => [ |
||
250 | ['data' => $class], |
||
251 | ['data' => new AtLeast(['attr1', 'attr2'], min: 2, message: 'Attributes - {attributes}, min - {min}.')], |
||
252 | ['data' => ['Attributes - "attr1", "attr2", min - 2.']], |
||
253 | ], |
||
254 | 'class attribute' => [ |
||
255 | new AtLeastDto(), |
||
256 | null, |
||
257 | ['' => ['At least 1 attribute from this list must be filled: "A", "B", "C".']], |
||
258 | ], |
||
278 |