| Conditions | 14 |
| Paths | 11 |
| Total Lines | 35 |
| Code Lines | 17 |
| 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 |
||
| 68 | public function validate(string $string): bool |
||
| 69 | { |
||
| 70 | if (mb_strlen($string) < $this->password->getLength()) { |
||
| 71 | throw new ValidationException(sprintf(__('Es necesaria una clave con al menos %d caracteres'), $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('La clave no cumple los carácteres requeridos'), ValidationException::ERROR, $regex); |
||
| 78 | } |
||
| 79 | |||
| 80 | if ($this->password->isUseLetters()) { |
||
| 81 | if (!Validator::hasLetters($string)) { |
||
| 82 | throw new ValidationException(__u('Es necesario que la clave contenga letras')); |
||
| 83 | } |
||
| 84 | |||
| 85 | if ($this->password->isUseLower() && !Validator::hasLower($string)) { |
||
| 86 | throw new ValidationException(__u('Es necesario que la clave contenga minúsculas')); |
||
| 87 | } |
||
| 88 | |||
| 89 | if ($this->password->isUseUpper() && !Validator::hasUpper($string)) { |
||
| 90 | throw new ValidationException(__u('Es necesario que la clave contenga mayúsculas')); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | if ($this->password->isUseNumbers() && !Validator::hasNumbers($string)) { |
||
| 95 | throw new ValidationException(__u('Es necesario que la clave contenga números')); |
||
| 96 | } |
||
| 97 | |||
| 98 | if ($this->password->isUseSymbols() && !Validator::hasSymbols($string)) { |
||
| 99 | throw new ValidationException(__u('Es necesario que la clave contenga símbolos')); |
||
| 100 | } |
||
| 101 | |||
| 102 | return true; |
||
| 103 | } |
||
| 104 | } |