| Conditions | 5 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 28 |
| 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 |
||
| 16 | public function boot() |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * Extend the Laravel Validator with the "zxcvbn_min" rule |
||
| 20 | */ |
||
| 21 | Validator::extend('zxcvbn_min', function($attribute, $value, $parameters) { |
||
| 22 | $zxcvbn = new ZxcvbnPhp(); |
||
| 23 | $zxcvbn = $zxcvbn->passwordStrength($value); |
||
| 24 | $target = 5; |
||
| 25 | |||
| 26 | if (isset($parameters[0])) { |
||
| 27 | $target = $parameters[0]; |
||
| 28 | } |
||
| 29 | |||
| 30 | return ($zxcvbn['score'] >= $target); |
||
| 31 | }, 'Your :attribute is not secure enough.'); |
||
| 32 | |||
| 33 | Validator::replacer('zxcvbn_min', function($message, $attribute) { |
||
| 34 | $message = str_replace(':attribute', $attribute, $message); |
||
| 35 | return $message; |
||
| 36 | }); |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Extend the Laravel Validator with the "zxcvbn_min" rule |
||
| 40 | */ |
||
| 41 | Validator::extend('zxcvbn_dictionary', function($attribute, $value, $parameters) { |
||
| 42 | $email = null; |
||
| 43 | $username = null; |
||
| 44 | |||
| 45 | if (isset($parameters[0])) { |
||
| 46 | $email = $parameters[0]; |
||
| 47 | $username = $parameters[1]; |
||
| 48 | } |
||
| 49 | |||
| 50 | $zxcvbn = new ZxcvbnPhp(); |
||
| 51 | $zxcvbn = $zxcvbn->passwordStrength($value, [$username, $email]); |
||
| 52 | |||
| 53 | if (isset($zxcvbn['sequence'][0])) { |
||
| 54 | $dictionary = $zxcvbn['sequence'][0]; |
||
| 55 | if (isset($dictionary->dictionaryName)) { |
||
| 56 | return false; |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | return true; |
||
| 61 | |||
| 62 | }, 'Your :attribute is insecure. It either matches a commonly used password, or you have used a similar username/password combination.'); |
||
| 63 | |||
| 64 | Validator::replacer('zxcvbn_dictionary', function($message, $attribute) { |
||
| 65 | $message = str_replace(':attribute', $attribute, $message); |
||
| 66 | return $message; |
||
| 67 | }); |
||
| 82 |