| Conditions | 1 |
| Paths | 1 |
| Total Lines | 132 |
| Code Lines | 95 |
| 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 |
||
| 205 | public function dataValidationFailed(): array |
||
| 206 | { |
||
| 207 | $rule = new Email(); |
||
| 208 | $ruleAllowedName = new Email(allowName: true); |
||
| 209 | $ruleEnabledIdn = new Email(enableIdn: true); |
||
| 210 | $ruleEnabledIdnAndAllowedName = new Email(allowName: true, enableIdn: true); |
||
| 211 | $errors = ['' => ['This value is not a valid email address.']]; |
||
| 212 | $incorrectInputErrors = ['' => ['The value must be a string.']]; |
||
| 213 | |||
| 214 | return [ |
||
| 215 | 'incorrect input, integer' => [1, [$rule], $incorrectInputErrors], |
||
| 216 | 'incorrect input, array containing string element' => [ |
||
| 217 | ['[email protected]'], |
||
| 218 | [$ruleAllowedName], |
||
| 219 | $incorrectInputErrors, |
||
| 220 | ], |
||
| 221 | 'custom incorrect input message' => [ |
||
| 222 | 1, |
||
| 223 | [new Email(incorrectInputMessage: 'Custom incorrect input message.')], |
||
| 224 | ['' => ['Custom incorrect input message.']], |
||
| 225 | ], |
||
| 226 | 'custom incorrect input message with parameters' => [ |
||
| 227 | 1, |
||
| 228 | [new Email(incorrectInputMessage: 'Attribute - {attribute}, type - {type}.')], |
||
| 229 | ['' => ['Attribute - , type - int.']], |
||
| 230 | ], |
||
| 231 | 'custom incorrect input message with parameters, attribute set' => [ |
||
| 232 | ['data' => 1], |
||
| 233 | ['data' => [new Email(incorrectInputMessage: 'Attribute - {attribute}, type - {type}.')]], |
||
| 234 | ['data' => ['Attribute - data, type - int.']], |
||
| 235 | ], |
||
| 236 | |||
| 237 | ['rmcreative.ru', [$rule], $errors], |
||
| 238 | ['Carsten Brandt <[email protected]>', [$rule], $errors], |
||
| 239 | ['"Carsten Brandt" <[email protected]>', [$rule], $errors], |
||
| 240 | ['<[email protected]>', [$rule], $errors], |
||
| 241 | ['info@örtliches.de', [$rule], $errors], |
||
| 242 | ['sam@рмкреатиф.ru', [$rule], $errors], |
||
| 243 | ['[email protected]', [$rule], $errors], |
||
| 244 | [str_repeat('a', 65) . '@gmail.com', [$rule], $errors], |
||
| 245 | ['name@' . str_repeat('a', 246) . '.com', [$rule], $errors], |
||
| 246 | |||
| 247 | // Malicious email addresses that can be used to exploit SwiftMailer vulnerability CVE-2016-10074 while IDN |
||
| 248 | // is disabled. |
||
| 249 | // https://legalhackers.com/advisories/SwiftMailer-Exploit-Remote-Code-Exec-CVE-2016-10074-Vuln.html |
||
| 250 | |||
| 251 | // This is the demo email used in the proof of concept of the exploit |
||
| 252 | ['"attacker\" -oQ/tmp/ -X/var/www/cache/phpcode.php "@email.com', [$rule], $errors], |
||
| 253 | |||
| 254 | // Trying more addresses |
||
| 255 | ['"Attacker -Param2 -Param3"@test.com', [$rule], $errors], |
||
| 256 | ['\'Attacker -Param2 -Param3\'@test.com', [$rule], $errors], |
||
| 257 | ['"Attacker \" -Param2 -Param3"@test.com', [$rule], $errors], |
||
| 258 | ["'Attacker \\' -Param2 -Param3'@test.com", [$rule], $errors], |
||
| 259 | ['"attacker\" -oQ/tmp/ -X/var/www/cache/phpcode.php "@email.com', [$rule], $errors], |
||
| 260 | |||
| 261 | // And even more variants |
||
| 262 | ['"attacker\"\ -oQ/tmp/\ -X/var/www/cache/phpcode.php"@email.com', [$rule], $errors], |
||
| 263 | ["\"attacker\\\"\0-oQ/tmp/\0-X/var/www/cache/phpcode.php\"@email.com", [$rule], $errors], |
||
| 264 | ['"[email protected]\"-Xbeep"@email.com', [$rule], $errors], |
||
| 265 | ["'attacker\\' -oQ/tmp/ -X/var/www/cache/phpcode.php'@email.com", [$rule], $errors], |
||
| 266 | ["'attacker\\\\' -oQ/tmp/ -X/var/www/cache/phpcode.php'@email.com", [$rule], $errors], |
||
| 267 | ["'attacker\\\\'\\ -oQ/tmp/ -X/var/www/cache/phpcode.php'@email.com", [$rule], $errors], |
||
| 268 | ["'attacker\\';touch /tmp/hackme'@email.com", [$rule], $errors], |
||
| 269 | ["'attacker\\\\';touch /tmp/hackme'@email.com", [$rule], $errors], |
||
| 270 | ["'attacker\\';touch/tmp/hackme'@email.com", [$rule], $errors], |
||
| 271 | ["'attacker\\\\';touch/tmp/hackme'@email.com", [$rule], $errors], |
||
| 272 | ['"attacker\" -oQ/tmp/ -X/var/www/cache/phpcode.php "@email.com', [$rule], $errors], |
||
| 273 | |||
| 274 | ['rmcreative.ru', [$ruleAllowedName], $errors], |
||
| 275 | ['info@örtliches.de', [$ruleAllowedName], $errors], |
||
| 276 | ['üñîçøðé@üñîçøðé.com', [$ruleAllowedName], $errors], |
||
| 277 | ['sam@рмкреатиф.ru', [$ruleAllowedName], $errors], |
||
| 278 | ['Informtation [email protected]', [$ruleAllowedName], $errors], |
||
| 279 | ['John Smith <example.com>', [$ruleAllowedName], $errors], |
||
| 280 | [ |
||
| 281 | 'Short Name <localPartMoreThan64Characters-blah-blah-blah-blah-blah-blah-blah-blah@example.com>', |
||
| 282 | [$ruleAllowedName], |
||
| 283 | $errors, |
||
| 284 | ], |
||
| 285 | [ |
||
| 286 | 'Short Name <domainNameIsMoreThan254Characters@example-blah-blah-blah-blah-blah-blah-blah-blah-blah-' . |
||
| 287 | 'blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-' . |
||
| 288 | 'blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah-blah' . |
||
| 289 | '.com>', |
||
| 290 | [$ruleAllowedName], |
||
| 291 | $errors, |
||
| 292 | ], |
||
| 293 | |||
| 294 | ['rmcreative.ru', [$ruleEnabledIdn], $errors], |
||
| 295 | ['Carsten Brandt <[email protected]>', [$ruleEnabledIdn], $errors], |
||
| 296 | ['"Carsten Brandt" <[email protected]>', [$ruleEnabledIdn], $errors], |
||
| 297 | ['<[email protected]>', [$ruleEnabledIdn], $errors], |
||
| 298 | |||
| 299 | [ |
||
| 300 | 'Короткое имя <тест@это-доменное-имя.после-преобразования-в-idn.будет-содержать-больше-254-символов.' . |
||
| 301 | 'бла-бла-бла-бла-бла-бла-бла-бла.бла-бла-бла-бла-бла-бла.бла-бла-бла-бла-бла-бла.бла-бла-бла-бла-бла-' . |
||
| 302 | 'бла.com>', |
||
| 303 | [$ruleEnabledIdnAndAllowedName], |
||
| 304 | $errors, |
||
| 305 | ], |
||
| 306 | ['Information info@örtliches.de', [$ruleEnabledIdnAndAllowedName], $errors], |
||
| 307 | ['rmcreative.ru', [$ruleEnabledIdnAndAllowedName], $errors], |
||
| 308 | ['John Smith <example.com>', [$ruleEnabledIdnAndAllowedName], $errors], |
||
| 309 | [ |
||
| 310 | 'Короткое имя <после-преобразования-в-idn-тут-будет-больше-чем-64-символа@пример.com>', |
||
| 311 | [$ruleEnabledIdnAndAllowedName], |
||
| 312 | $errors, |
||
| 313 | ], |
||
| 314 | |||
| 315 | ['name@ñandu.cl', [new Email(checkDns: true)], $errors], |
||
| 316 | ['gmail.con', [new Email(checkDns: true)], $errors], |
||
| 317 | [ |
||
| 318 | '[email protected]', |
||
| 319 | [new Email(checkDns: true)], |
||
| 320 | $errors, |
||
| 321 | ], |
||
| 322 | |||
| 323 | 'custom message' => [ |
||
| 324 | '[email protected]', |
||
| 325 | [new Email(checkDns: true, message: 'Custom message.')], |
||
| 326 | ['' => ['Custom message.']], |
||
| 327 | ], |
||
| 328 | 'custom message with parameters' => [ |
||
| 329 | '[email protected]', |
||
| 330 | [new Email(checkDns: true, message: 'Attribute - {attribute}, value - {value}.')], |
||
| 331 | ['' => ['Attribute - , value - [email protected].']], |
||
| 332 | ], |
||
| 333 | 'custom message with parameters, attribute set' => [ |
||
| 334 | ['data' => '[email protected]'], |
||
| 335 | ['data' => new Email(checkDns: true, message: 'Attribute - {attribute}, value - {value}.')], |
||
| 336 | ['data' => ['Attribute - data, value - [email protected].']], |
||
| 337 | ], |
||
| 357 |