| Conditions | 8 |
| Paths | 128 |
| Total Lines | 59 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 7 | static public function evaluateStrength(string $password): array |
||
| 8 | { |
||
| 9 | $rules = []; |
||
| 10 | |||
| 11 | if (strlen($password) >= 10) { |
||
| 12 | $rules['passwordTooShort'] = false; |
||
| 13 | } else { |
||
| 14 | $rules['passwordTooShort'] = true; |
||
| 15 | } |
||
| 16 | |||
| 17 | if (preg_match('/[a-z]/', $password)) { |
||
| 18 | $rules['noLowercase'] = false; |
||
| 19 | } else { |
||
| 20 | $rules['noLowercase'] = true; |
||
| 21 | } |
||
| 22 | |||
| 23 | if (preg_match('/[A-Z]/', $password)) { |
||
| 24 | $rules['noUppercase'] = false; |
||
| 25 | } else { |
||
| 26 | $rules['noUppercase'] = true; |
||
| 27 | } |
||
| 28 | |||
| 29 | if (preg_match('/[0-9]/', $password)) { |
||
| 30 | $rules['noNumber'] = false; |
||
| 31 | } else { |
||
| 32 | $rules['noNumber'] = true; |
||
| 33 | } |
||
| 34 | |||
| 35 | if (preg_match('/[\W_]/', $password)) { |
||
| 36 | $rules['noSymbol'] = false; |
||
| 37 | } else { |
||
| 38 | $rules['noSymbol'] = true; |
||
| 39 | } |
||
| 40 | |||
| 41 | /* |
||
| 42 | $types = 0; |
||
| 43 | $types += preg_match('/[a-z]/', $password); |
||
| 44 | $types += preg_match('/[A-Z]/', $password); |
||
| 45 | $types += preg_match('/[0-9]/', $password); |
||
| 46 | $types += preg_match('/[\W_]/', $password); |
||
| 47 | if ($types >= 3) { |
||
| 48 | $score += $variationWeight; |
||
| 49 | } |
||
| 50 | */ |
||
| 51 | |||
| 52 | if (preg_match('/(.)\1{3,}/', $password)) { |
||
| 53 | $rules['passwordRepeating'] = true; |
||
| 54 | } else { |
||
| 55 | $rules['passwordRepeating'] = false; |
||
| 56 | } |
||
| 57 | |||
| 58 | $common = ['123456', 'password', 'qwerty', 'admin', 'letmein']; |
||
| 59 | if (in_array(strtolower($password), $common)) { |
||
| 60 | $rules['commonPassword'] = true; |
||
| 61 | } else { |
||
| 62 | $rules['commonPassword'] = false; |
||
| 63 | } |
||
| 64 | |||
| 65 | return $rules; |
||
| 66 | } |
||
| 67 | } |