| Conditions | 11 |
| Paths | 26 |
| Total Lines | 45 |
| Code Lines | 23 |
| 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 |
||
| 81 | protected function isValid($value) |
||
| 82 | { |
||
| 83 | $result = true; |
||
| 84 | $settings = $this->settingsService->getSettings(); |
||
| 85 | |||
| 86 | // Early return if no passwords are given |
||
| 87 | if ($value->getPassword1() === '' || $value->getPassword2() === '') { |
||
| 88 | $this->addError( |
||
| 89 | $this->localizationService->translate('passwordFieldsEmptyOrNotBothFilledOut'), |
||
| 90 | 1537701950 |
||
| 91 | ); |
||
| 92 | |||
| 93 | return false; |
||
| 94 | } |
||
| 95 | |||
| 96 | if ($value->getPassword1() !== $value->getPassword2()) { |
||
| 97 | $this->addError( |
||
| 98 | $this->localizationService->translate('passwordsDoNotMatch'), |
||
| 99 | 1537701950 |
||
| 100 | ); |
||
| 101 | // Early return, no other checks need to be done if passwords do not match |
||
| 102 | return false; |
||
| 103 | } |
||
| 104 | |||
| 105 | if (isset($settings['passwordComplexity']['minLength'])) { |
||
| 106 | $this->evaluateMinLengthCheck($value, (int)$settings['passwordComplexity']['minLength']); |
||
| 107 | } |
||
| 108 | |||
| 109 | foreach ($this->checks as $check) { |
||
| 110 | if (isset($settings['passwordComplexity'][$check]) && |
||
| 111 | (bool)$settings['passwordComplexity'][$check] |
||
| 112 | ) { |
||
| 113 | $this->evaluatePasswordCheck($value, $check); |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | if (isset($settings['pwnedpasswordsCheck']['enabled']) && (bool)$settings['pwnedpasswordsCheck']['enabled']) { |
||
| 118 | $this->evaluatePwnedPasswordCheck($value); |
||
| 119 | } |
||
| 120 | |||
| 121 | if ($this->result->hasErrors()) { |
||
| 122 | $result = false; |
||
| 123 | } |
||
| 124 | |||
| 125 | return $result; |
||
| 126 | } |
||
| 182 |