| Conditions | 1 |
| Total Lines | 68 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 148 | public function dataValidationFailed(): array |
||
| 149 | { |
||
| 150 | $object = new class () { |
||
| 151 | public $attr1 = null; |
||
| 152 | public $attr2 = null; |
||
| 153 | }; |
||
| 154 | $array = ['attr1' => null, 'attr2' => null]; |
||
| 155 | |||
| 156 | return [ |
||
| 157 | 'incorrect input' => [ |
||
| 158 | 1, |
||
| 159 | [new OneOf(['attr1', 'attr2'])], |
||
| 160 | ['' => ['The value must be an array or an object.']], |
||
| 161 | ], |
||
| 162 | 'custom incorrect input message' => [ |
||
| 163 | 1, |
||
| 164 | [new OneOf(['attr1', 'attr2'], incorrectInputMessage: 'Custom incorrect input message.')], |
||
| 165 | ['' => ['Custom incorrect input message.']], |
||
| 166 | ], |
||
| 167 | 'custom incorrect input message with parameters' => [ |
||
| 168 | 1, |
||
| 169 | [new OneOf(['attr1', 'attr2'], incorrectInputMessage: 'Attribute - {attribute}, type - {type}.')], |
||
| 170 | ['' => ['Attribute - , type - int.']], |
||
| 171 | ], |
||
| 172 | 'custom incorrect input message with parameters, attribute set' => [ |
||
| 173 | ['attribute' => 1], |
||
| 174 | [ |
||
| 175 | 'attribute' => new OneOf( |
||
| 176 | ['attr1', 'attr2'], |
||
| 177 | incorrectInputMessage: 'Attribute - {attribute}, type - {type}.', |
||
| 178 | ), |
||
| 179 | ], |
||
| 180 | ['attribute' => ['Attribute - attribute, type - int.']], |
||
| 181 | ], |
||
| 182 | 'object' => [ |
||
| 183 | $object, |
||
| 184 | [new OneOf(['attr1', 'attr2'])], |
||
| 185 | ['' => ['Exactly 1 attribute from this list must be filled: "attr1", "attr2".']], |
||
| 186 | ], |
||
| 187 | 'array' => [ |
||
| 188 | $array, |
||
| 189 | [new OneOf(['attr1', 'attr2'])], |
||
| 190 | ['' => ['Exactly 1 attribute from this list must be filled: "attr1", "attr2".']], |
||
| 191 | ], |
||
| 192 | 'more than 1 attribute is filled' => [ |
||
| 193 | ['attr1' => 1, 'attr2' => 2], |
||
| 194 | [new OneOf(['attr1', 'attr2'])], |
||
| 195 | ['' => ['Exactly 1 attribute from this list must be filled: "attr1", "attr2".']], |
||
| 196 | ], |
||
| 197 | 'custom message' => [ |
||
| 198 | $object, |
||
| 199 | [new OneOf(['attr1', 'attr2'], message: 'Custom message.')], |
||
| 200 | ['' => ['Custom message.']], |
||
| 201 | ], |
||
| 202 | 'custom message with parameters' => [ |
||
| 203 | $object, |
||
| 204 | [new OneOf(['attr1', 'attr2'], message: 'Attributes - {attributes}.')], |
||
| 205 | ['' => ['Attributes - "attr1", "attr2".']], |
||
| 206 | ], |
||
| 207 | 'custom message with parameters, attribute set' => [ |
||
| 208 | ['data' => $object], |
||
| 209 | ['data' => new OneOf(['attr1', 'attr2'], message: 'Attributes - {attributes}.')], |
||
| 210 | ['data' => ['Attributes - "attr1", "attr2".']], |
||
| 211 | ], |
||
| 212 | 'class attribute' => [ |
||
| 213 | new OneOfDto(), |
||
| 214 | null, |
||
| 215 | ['' => ['Exactly 1 attribute from this list must be filled: "A", "B", "C".']], |
||
| 216 | ], |
||
| 236 |