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