| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 112 | 
| Code Lines | 75 | 
| 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 | ||
| 142 | public function dataValidationFailed(): array | ||
| 143 |     { | ||
| 144 | $incorrectInputMessage = 'This value must be a string.'; | ||
| 145 | $greaterThanMaxMessage = 'This value must contain at most 25 characters.'; | ||
| 146 | $notExactlyMessage = 'This value must contain exactly 25 characters.'; | ||
| 147 | $lessThanMinMessage = 'This value must contain at least 25 characters.'; | ||
| 148 | |||
| 149 | return [ | ||
| 150 | 'incorrect input, array' => [['not a string'], [new HasLength(min: 25)], ['' => [$incorrectInputMessage]]], | ||
| 151 | 'incorrect input, boolean (true)' => [true, [new HasLength(min: 25)], ['' => [$incorrectInputMessage]]], | ||
| 152 | 'incorrect input, boolean (false)' => [false, [new HasLength(min: 25)], ['' => [$incorrectInputMessage]]], | ||
| 153 | 'custom incorrect input message' => [ | ||
| 154 | false, | ||
| 155 | [new HasLength(min: 25, incorrectInputMessage: 'Custom incorrect input message.')], | ||
| 156 | ['' => ['Custom incorrect input message.']], | ||
| 157 | ], | ||
| 158 | 'custom incorrect input message with parameters' => [ | ||
| 159 | false, | ||
| 160 |                 [new HasLength(min: 25, incorrectInputMessage: 'Attribute - {attribute}, type - {type}.')], | ||
| 161 | ['' => ['Attribute - , type - bool.']], | ||
| 162 | ], | ||
| 163 | 'custom incorrect input message with parameters, attribute set' => [ | ||
| 164 | ['data' => false], | ||
| 165 |                 ['data' => new HasLength(min: 25, incorrectInputMessage: 'Attribute - {attribute}, type - {type}.')], | ||
| 166 | ['data' => ['Attribute - data, type - bool.']], | ||
| 167 | ], | ||
| 168 | |||
| 169 | [new SingleValueDataSet(new stdClass()), [new HasLength(min: 25)], ['' => [$incorrectInputMessage]]], | ||
| 170 | |||
| 171 |             [str_repeat('x', 1250), [new HasLength(max: 25)], ['' => [$greaterThanMaxMessage]]], | ||
| 172 |             [str_repeat('x', 125), [new HasLength(exactly: 25)], ['' => [$notExactlyMessage]]], | ||
| 173 | |||
| 174 | ['', [new HasLength(exactly: 25)], ['' => [$notExactlyMessage]]], | ||
| 175 | [ | ||
| 176 |                 str_repeat('x', 5), | ||
| 177 | [new HasLength(min: 10, max: 25)], | ||
| 178 | ['' => ['This value must contain at least 10 characters.']], | ||
| 179 | ], | ||
| 180 |             [str_repeat('x', 13), [new HasLength(min: 25)], ['' => [$lessThanMinMessage]]], | ||
| 181 | ['', [new HasLength(min: 25)], ['' => [$lessThanMinMessage]]], | ||
| 182 | |||
| 183 | 'custom less than min message' => [ | ||
| 184 | 'ab', | ||
| 185 | [new HasLength(min: 3, lessThanMinMessage: 'Custom less than min message.')], | ||
| 186 | ['' => ['Custom less than min message.']], | ||
| 187 | ], | ||
| 188 | 'custom less than min message with parameters' => [ | ||
| 189 | 'ab', | ||
| 190 |                 [new HasLength(min: 3, lessThanMinMessage: 'Min - {min}, attribute - {attribute}, number - {number}.')], | ||
| 191 | ['' => ['Min - 3, attribute - , number - 2.']], | ||
| 192 | ], | ||
| 193 | 'custom less than min message with parameters, attribute set' => [ | ||
| 194 | ['data' => 'ab'], | ||
| 195 | [ | ||
| 196 | 'data' => new HasLength( | ||
| 197 | min: 3, | ||
| 198 |                         lessThanMinMessage: 'Min - {min}, attribute - {attribute}, number - {number}.', | ||
| 199 | ), | ||
| 200 | ], | ||
| 201 | ['data' => ['Min - 3, attribute - data, number - 2.']], | ||
| 202 | ], | ||
| 203 | |||
| 204 | 'custom greater than max message' => [ | ||
| 205 | 'abcd', | ||
| 206 | [new HasLength(max: 3, greaterThanMaxMessage: 'Custom greater than max message.')], | ||
| 207 | ['' => ['Custom greater than max message.']], | ||
| 208 | ], | ||
| 209 | 'custom greater than max message with parameters' => [ | ||
| 210 | 'abcd', | ||
| 211 | [ | ||
| 212 | new HasLength( | ||
| 213 | max: 3, | ||
| 214 |                         greaterThanMaxMessage: 'Max - {max}, attribute - {attribute}, number - {number}.', | ||
| 215 | ), | ||
| 216 | ], | ||
| 217 | ['' => ['Max - 3, attribute - , number - 4.']], | ||
| 218 | ], | ||
| 219 | 'custom greater than max message with parameters, attribute set' => [ | ||
| 220 | ['data' => 'abcd'], | ||
| 221 | [ | ||
| 222 | 'data' => new HasLength( | ||
| 223 | max: 3, | ||
| 224 |                         greaterThanMaxMessage: 'Max - {max}, attribute - {attribute}, number - {number}.', | ||
| 225 | ), | ||
| 226 | ], | ||
| 227 | ['data' => ['Max - 3, attribute - data, number - 4.']], | ||
| 228 | ], | ||
| 229 | |||
| 230 | 'custom not exactly message' => [ | ||
| 231 | 'abcd', | ||
| 232 | [new HasLength(exactly: 3, notExactlyMessage: 'Custom not exactly message.')], | ||
| 233 | ['' => ['Custom not exactly message.']], | ||
| 234 | ], | ||
| 235 | 'custom not exactly message with parameters' => [ | ||
| 236 | 'abcd', | ||
| 237 | [ | ||
| 238 | new HasLength( | ||
| 239 | exactly: 3, | ||
| 240 |                         notExactlyMessage: 'Exactly - {exactly}, attribute - {attribute}, number - {number}.', | ||
| 241 | ), | ||
| 242 | ], | ||
| 243 | ['' => ['Exactly - 3, attribute - , number - 4.']], | ||
| 244 | ], | ||
| 245 | 'custom not exactly message with parameters, attribute set' => [ | ||
| 246 | ['data' => 'abcd'], | ||
| 247 | [ | ||
| 248 | 'data' => new HasLength( | ||
| 249 | exactly: 3, | ||
| 250 |                         notExactlyMessage: 'Exactly - {exactly}, attribute - {attribute}, number - {number}.', | ||
| 251 | ), | ||
| 252 | ], | ||
| 253 | ['data' => ['Exactly - 3, attribute - data, number - 4.']], | ||
| 254 | ], | ||
| 279 |