| Total Lines | 73 | 
| Code Lines | 52 | 
| 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 |         $class = new class () { | ||
| 173 | public $attr1 = 1; | ||
| 174 | public $attr2 = null; | ||
| 175 | }; | ||
| 176 | $array = ['attr1' => 1, 'attr2' => null]; | ||
| 177 | |||
| 178 | return [ | ||
| 179 | 'incorrect input' => [ | ||
| 180 | 1, | ||
| 181 | [new AtLeast(['attr2'])], | ||
| 182 | ['' => ['Value must be an array or an object.']], | ||
| 183 | ], | ||
| 184 | 'custom incorrect input message' => [ | ||
| 185 | 1, | ||
| 186 | [new AtLeast(['attr2'], incorrectInputMessage: 'Custom incorrect input message.')], | ||
| 187 | ['' => ['Custom incorrect input message.']], | ||
| 188 | ], | ||
| 189 | 'custom incorrect input message with parameters' => [ | ||
| 190 | 1, | ||
| 191 |                 [new AtLeast(['attr2'], incorrectInputMessage: 'Attribute - {attribute}, type - {type}.')], | ||
| 192 | ['' => ['Attribute - , type - int.']], | ||
| 193 | ], | ||
| 194 | 'custom incorrect input message with parameters, attribute set' => [ | ||
| 195 | ['attribute' => 1], | ||
| 196 | [ | ||
| 197 | 'attribute' => new AtLeast( | ||
| 198 | ['attr2'], | ||
| 199 |                         incorrectInputMessage: 'Attribute - {attribute}, type - {type}.', | ||
| 200 | ), | ||
| 201 | ], | ||
| 202 | ['attribute' => ['Attribute - attribute, type - int.']], | ||
| 203 | ], | ||
| 204 | 'object' => [ | ||
| 205 | $class, | ||
| 206 | [new AtLeast(['attr2'])], | ||
| 207 | ['' => ['The data must have at least "1" filled attributes.']], | ||
| 208 | ], | ||
| 209 | 'object, custom min' => [ | ||
| 210 | $class, | ||
| 211 | [new AtLeast(['attr1', 'attr2'], min: 2)], | ||
| 212 | ['' => ['The data must have at least "2" filled attributes.']], | ||
| 213 | ], | ||
| 214 | 'array' => [ | ||
| 215 | $array, | ||
| 216 | [new AtLeast(['attr2'])], | ||
| 217 | ['' => ['The data must have at least "1" filled attributes.']], | ||
| 218 | ], | ||
| 219 | 'array, custom min' => [ | ||
| 220 | $array, | ||
| 221 | [new AtLeast(['attr2'], min: 2)], | ||
| 222 | ['' => ['The data must have at least "2" filled attributes.']], | ||
| 223 | ], | ||
| 224 | 'custom message' => [ | ||
| 225 | $class, | ||
| 226 | [new AtLeast(['attr1', 'attr2'], min: 2, message: 'Custom message.')], | ||
| 227 | ['' => ['Custom message.']], | ||
| 228 | ], | ||
| 229 | 'custom message with parameters' => [ | ||
| 230 | $class, | ||
| 231 |                 [new AtLeast(['attr1', 'attr2'], min: 2, message: 'Attribute - {attribute}, min - {min}.')], | ||
| 232 | ['' => ['Attribute - , min - 2.']], | ||
| 233 | ], | ||
| 234 | 'custom message with parameters, attribute set' => [ | ||
| 235 | ['data' => $class], | ||
| 236 |                 ['data' => new AtLeast(['attr1', 'attr2'], min: 2, message: 'Attribute - {attribute}, min - {min}.')], | ||
| 237 | ['data' => ['Attribute - data, min - 2.']], | ||
| 238 | ], | ||
| 239 | 'class attribute' => [ | ||
| 240 | new AtLeastDto(), | ||
| 241 | null, | ||
| 242 | ['' => ['The data must have at least "1" filled attributes.']], | ||
| 243 | ], | ||
| 263 |