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