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