Conditions | 14 |
Paths | 11 |
Total Lines | 35 |
Code Lines | 17 |
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 |
||
68 | public function validate(string $string): bool |
||
69 | { |
||
70 | if (mb_strlen($string) < $this->password->getLength()) { |
||
71 | throw new ValidationException(sprintf(__('Password needs to be %d characters long'), $this->password->getLength())); |
||
72 | } |
||
73 | |||
74 | $regex = $this->password->getRegex(); |
||
75 | |||
76 | if (!empty($this->password->getRegex()) && !Validator::matchRegex($string, $regex)) { |
||
77 | throw new ValidationException(__u('Password does not contain the required characters'), ValidationException::ERROR, $regex); |
||
78 | } |
||
79 | |||
80 | if ($this->password->isUseLetters()) { |
||
81 | if (!Validator::hasLetters($string)) { |
||
82 | throw new ValidationException(__u('Password needs to contain letters')); |
||
83 | } |
||
84 | |||
85 | if ($this->password->isUseLower() && !Validator::hasLower($string)) { |
||
86 | throw new ValidationException(__u('Password needs to contain lower case letters')); |
||
87 | } |
||
88 | |||
89 | if ($this->password->isUseUpper() && !Validator::hasUpper($string)) { |
||
90 | throw new ValidationException(__u('Password needs to contain upper case letters')); |
||
91 | } |
||
92 | } |
||
93 | |||
94 | if ($this->password->isUseNumbers() && !Validator::hasNumbers($string)) { |
||
95 | throw new ValidationException(__u('Password needs to contain numbers')); |
||
96 | } |
||
97 | |||
98 | if ($this->password->isUseSymbols() && !Validator::hasSymbols($string)) { |
||
99 | throw new ValidationException(__u('Password needs to contain symbols')); |
||
100 | } |
||
101 | |||
102 | return true; |
||
103 | } |
||
104 | } |