| Conditions | 1 |
| Paths | 1 |
| Total Lines | 124 |
| Code Lines | 84 |
| 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 |
||
| 159 | public function dataValidationFailed(): array |
||
| 160 | { |
||
| 161 | $incorrectInputMessage = 'The value must be a string.'; |
||
| 162 | $greaterThanMaxMessage = 'This value must contain at most 25 characters.'; |
||
| 163 | $notExactlyMessage = 'This value must contain exactly 25 characters.'; |
||
| 164 | $lessThanMinMessage = 'This value must contain at least 25 characters.'; |
||
| 165 | |||
| 166 | return [ |
||
| 167 | 'incorrect input, array' => [['not a string'], [new Length(min: 25)], ['' => [$incorrectInputMessage]]], |
||
| 168 | 'incorrect input, boolean (true)' => [true, [new Length(min: 25)], ['' => [$incorrectInputMessage]]], |
||
| 169 | 'incorrect input, boolean (false)' => [false, [new Length(min: 25)], ['' => [$incorrectInputMessage]]], |
||
| 170 | 'custom incorrect input message' => [ |
||
| 171 | false, |
||
| 172 | [new Length(min: 25, incorrectInputMessage: 'Custom incorrect input message.')], |
||
| 173 | ['' => ['Custom incorrect input message.']], |
||
| 174 | ], |
||
| 175 | 'custom incorrect input message with parameters' => [ |
||
| 176 | false, |
||
| 177 | [new Length(min: 25, incorrectInputMessage: 'Attribute - {attribute}, type - {type}.')], |
||
| 178 | ['' => ['Attribute - , type - bool.']], |
||
| 179 | ], |
||
| 180 | 'custom incorrect input message with parameters, attribute set' => [ |
||
| 181 | ['data' => false], |
||
| 182 | ['data' => new Length(min: 25, incorrectInputMessage: 'Attribute - {attribute}, type - {type}.')], |
||
| 183 | ['data' => ['Attribute - data, type - bool.']], |
||
| 184 | ], |
||
| 185 | |||
| 186 | [new SingleValueDataSet(new stdClass()), [new Length(min: 25)], ['' => [$incorrectInputMessage]]], |
||
| 187 | |||
| 188 | [str_repeat('x', 1250), [new Length(max: 25)], ['' => [$greaterThanMaxMessage]]], |
||
| 189 | [str_repeat('x', 125), [new Length(exactly: 25)], ['' => [$notExactlyMessage]]], |
||
| 190 | |||
| 191 | ['', [new Length(exactly: 25)], ['' => [$notExactlyMessage]]], |
||
| 192 | ['', [new Length(25)], ['' => [$notExactlyMessage]]], |
||
| 193 | [ |
||
| 194 | str_repeat('x', 5), |
||
| 195 | [new Length(min: 10, max: 25)], |
||
| 196 | ['' => ['This value must contain at least 10 characters.']], |
||
| 197 | ], |
||
| 198 | [str_repeat('x', 13), [new Length(min: 25)], ['' => [$lessThanMinMessage]]], |
||
| 199 | ['', [new Length(min: 25)], ['' => [$lessThanMinMessage]]], |
||
| 200 | |||
| 201 | 'custom less than min message' => [ |
||
| 202 | 'ab', |
||
| 203 | [new Length(min: 3, lessThanMinMessage: 'Custom less than min message.')], |
||
| 204 | ['' => ['Custom less than min message.']], |
||
| 205 | ], |
||
| 206 | 'custom less than min message with parameters' => [ |
||
| 207 | 'ab', |
||
| 208 | [new Length(min: 3, lessThanMinMessage: 'Min - {min}, attribute - {attribute}, number - {number}.')], |
||
| 209 | ['' => ['Min - 3, attribute - , number - 2.']], |
||
| 210 | ], |
||
| 211 | 'custom less than min message with parameters, attribute set' => [ |
||
| 212 | ['data' => 'ab'], |
||
| 213 | [ |
||
| 214 | 'data' => new Length( |
||
| 215 | min: 3, |
||
| 216 | lessThanMinMessage: 'Min - {min}, attribute - {attribute}, number - {number}.', |
||
| 217 | ), |
||
| 218 | ], |
||
| 219 | ['data' => ['Min - 3, attribute - data, number - 2.']], |
||
| 220 | ], |
||
| 221 | |||
| 222 | 'custom greater than max message' => [ |
||
| 223 | 'abcd', |
||
| 224 | [new Length(max: 3, greaterThanMaxMessage: 'Custom greater than max message.')], |
||
| 225 | ['' => ['Custom greater than max message.']], |
||
| 226 | ], |
||
| 227 | 'custom greater than max message with parameters' => [ |
||
| 228 | 'abcd', |
||
| 229 | [ |
||
| 230 | new Length( |
||
| 231 | max: 3, |
||
| 232 | greaterThanMaxMessage: 'Max - {max}, attribute - {attribute}, number - {number}.', |
||
| 233 | ), |
||
| 234 | ], |
||
| 235 | ['' => ['Max - 3, attribute - , number - 4.']], |
||
| 236 | ], |
||
| 237 | 'custom greater than max message with parameters, attribute set' => [ |
||
| 238 | ['data' => 'abcd'], |
||
| 239 | [ |
||
| 240 | 'data' => new Length( |
||
| 241 | max: 3, |
||
| 242 | greaterThanMaxMessage: 'Max - {max}, attribute - {attribute}, number - {number}.', |
||
| 243 | ), |
||
| 244 | ], |
||
| 245 | ['data' => ['Max - 3, attribute - data, number - 4.']], |
||
| 246 | ], |
||
| 247 | |||
| 248 | 'custom not exactly message' => [ |
||
| 249 | 'abcd', |
||
| 250 | [new Length(exactly: 3, notExactlyMessage: 'Custom not exactly message.')], |
||
| 251 | ['' => ['Custom not exactly message.']], |
||
| 252 | ], |
||
| 253 | 'custom not exactly message with parameters' => [ |
||
| 254 | 'abcd', |
||
| 255 | [ |
||
| 256 | new Length( |
||
| 257 | exactly: 3, |
||
| 258 | notExactlyMessage: 'Exactly - {exactly}, attribute - {attribute}, number - {number}.', |
||
| 259 | ), |
||
| 260 | ], |
||
| 261 | ['' => ['Exactly - 3, attribute - , number - 4.']], |
||
| 262 | ], |
||
| 263 | 'custom not exactly message with parameters, attribute set' => [ |
||
| 264 | ['data' => 'abcd'], |
||
| 265 | [ |
||
| 266 | 'data' => new Length( |
||
| 267 | exactly: 3, |
||
| 268 | notExactlyMessage: 'Exactly - {exactly}, attribute - {attribute}, number - {number}.', |
||
| 269 | ), |
||
| 270 | ], |
||
| 271 | ['data' => ['Exactly - 3, attribute - data, number - 4.']], |
||
| 272 | ], |
||
| 273 | |||
| 274 | 'value: string with greater count, exactly: 0' => [ |
||
| 275 | 'a', |
||
| 276 | [new Length(0)], |
||
| 277 | ['' => ['This value must contain exactly 0 characters.']], |
||
| 278 | ], |
||
| 279 | 'value: empty string, exactly: positive' => [ |
||
| 280 | '', |
||
| 281 | [new Length(1)], |
||
| 282 | ['' => ['This value must contain exactly 1 character.']], |
||
| 283 | ], |
||
| 308 |