Conditions | 11 |
Paths | 111 |
Total Lines | 35 |
Code Lines | 25 |
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 |
||
22 | public function validate($password, Constraint $constraint) |
||
23 | { |
||
24 | $pwdValidator = $constraint->getPwdValidator(); |
||
|
|||
25 | $pwdConfig = $constraint->getConfig()->getPwdSettings(); |
||
26 | if (true === $pwdConfig['enforce_min_length']) { |
||
27 | $pwdMinLength = $pwdConfig['min_length']; |
||
28 | if (mb_strlen($password, 'utf-8') < $pwdMinLength) { |
||
29 | $this->addError("Your password needs to be at least {$pwdMinLength} characters long", $password); |
||
30 | } |
||
31 | } |
||
32 | if (true === $pwdConfig['numbers']) { |
||
33 | switch (preg_match('/[0-9]/', $password)) { |
||
34 | case 0: |
||
35 | $this->addError('Your password needs to contain numbers.', $password); |
||
36 | break; |
||
37 | |||
38 | case false: |
||
39 | throw new Exception(); |
||
40 | break; |
||
41 | } |
||
42 | } |
||
43 | if (true === $pwdConfig['special_chars']) { |
||
44 | if (false === $pwdValidator->hasSpecialChars($password)) { |
||
45 | $this->addError('Your password needs to contain special characters', $password); |
||
46 | } |
||
47 | } |
||
48 | if (true === $pwdConfig['uppercase']) { |
||
49 | switch (preg_match('/[A-Z]/', $password)) { |
||
50 | case 0: |
||
51 | $this->addError('Your password needs to contain uppercase letters.', $password); |
||
52 | break; |
||
53 | |||
54 | case false: |
||
55 | throw new Exception(); |
||
56 | break; |
||
57 | } |
||
74 |