| Conditions | 14 |
| Paths | 7 |
| Total Lines | 33 |
| Code Lines | 18 |
| 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 |
||
| 64 | public function validate($content): bool |
||
| 65 | { |
||
| 66 | if (strlen($content) < $this->minLength || strlen($content) > $this->maxLength) { |
||
| 67 | return false; |
||
| 68 | } |
||
| 69 | |||
| 70 | $hasUpperCase = (bool) preg_match('/[A-Z]/', $content); |
||
| 71 | $hasLowerCase = (bool) preg_match('/[a-z]/', $content); |
||
| 72 | $hasDigits = (bool) preg_match('/[0-9]/', $content); |
||
| 73 | $hasSymbols = (bool) preg_match('/[^A-Za-z0-9]/', $content); |
||
| 74 | |||
| 75 | if ($this->mustHaveUpperCase && !$hasUpperCase) { |
||
| 76 | return false; |
||
| 77 | } |
||
| 78 | |||
| 79 | if ($this->mustHaveLowerCase && !$hasLowerCase) { |
||
| 80 | return false; |
||
| 81 | } |
||
| 82 | |||
| 83 | if ($this->mustHaveDigits && !$hasDigits) { |
||
| 84 | return false; |
||
| 85 | } |
||
| 86 | |||
| 87 | if ($this->mustHaveSymbols && !$hasSymbols) { |
||
| 88 | return false; |
||
| 89 | } |
||
| 90 | |||
| 91 | if ($this->mustHaveDigitsOrSymbols && (!$hasDigits && !$hasSymbols)) { |
||
|
|
|||
| 92 | return false; |
||
| 93 | } |
||
| 94 | |||
| 95 | return true; |
||
| 96 | } |
||
| 97 | } |
||
| 98 |