| Conditions | 17 |
| Paths | 101 |
| Total Lines | 60 |
| Code Lines | 31 |
| 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 |
||
| 55 | protected function isValid($value): bool |
||
| 56 | { |
||
| 57 | $result = true; |
||
| 58 | $settings = $this->settingsService->getSettings(); |
||
| 59 | |||
| 60 | // Early return if old password is required, but either empty or not valid |
||
| 61 | if (isset($settings['requireCurrentPassword']['enabled']) && |
||
| 62 | (bool)$settings['requireCurrentPassword']['enabled'] && |
||
| 63 | !$value->getSkipCurrentPasswordCheck() |
||
| 64 | ) { |
||
| 65 | $requireCurrentPasswordResult = $this->evaluateRequireCurrentPassword($value); |
||
| 66 | if ($requireCurrentPasswordResult === false) { |
||
| 67 | return false; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | // Early return if no passwords are given |
||
| 72 | if ($value->getPassword1() === '' || $value->getPassword2() === '') { |
||
| 73 | $this->addError( |
||
| 74 | $this->localizationService->translate('passwordFieldsEmptyOrNotBothFilledOut'), |
||
| 75 | 1537701950 |
||
| 76 | ); |
||
| 77 | |||
| 78 | return false; |
||
| 79 | } |
||
| 80 | |||
| 81 | if ($value->getPassword1() !== $value->getPassword2()) { |
||
| 82 | $this->addError( |
||
| 83 | $this->localizationService->translate('passwordsDoNotMatch'), |
||
| 84 | 1537701950 |
||
| 85 | ); |
||
| 86 | // Early return, no other checks need to be done if passwords do not match |
||
| 87 | return false; |
||
| 88 | } |
||
| 89 | |||
| 90 | if (isset($settings['passwordComplexity']['minLength'])) { |
||
| 91 | $this->evaluateMinLengthCheck($value, (int)$settings['passwordComplexity']['minLength']); |
||
| 92 | } |
||
| 93 | |||
| 94 | foreach ($this->checks as $check) { |
||
| 95 | if (isset($settings['passwordComplexity'][$check]) && |
||
| 96 | (bool)$settings['passwordComplexity'][$check] |
||
| 97 | ) { |
||
| 98 | $this->evaluatePasswordCheck($value, $check); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | if (isset($settings['pwnedpasswordsCheck']['enabled']) && (bool)$settings['pwnedpasswordsCheck']['enabled']) { |
||
| 103 | $this->evaluatePwnedPasswordCheck($value); |
||
| 104 | } |
||
| 105 | |||
| 106 | if (isset($settings['oldPasswordCheck']['enabled']) && (bool)$settings['oldPasswordCheck']['enabled']) { |
||
| 107 | $this->evaluateOldPasswordCheck($value); |
||
| 108 | } |
||
| 109 | |||
| 110 | if ($this->result->hasErrors()) { |
||
| 111 | $result = false; |
||
| 112 | } |
||
| 113 | |||
| 114 | return $result; |
||
| 115 | } |
||
| 219 |