| Conditions | 3 |
| Paths | 4 |
| Total Lines | 52 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | 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 namespace Anomaly\UsersModule\User\Password; |
||
| 19 | public function handle(ResetPasswordFormBuilder $builder) |
||
| 20 | { |
||
| 21 | $builder->setFields([]); |
||
| 22 | |||
| 23 | if (!$builder->getEmail()) { |
||
|
|
|||
| 24 | $builder->addField( |
||
| 25 | [ |
||
| 26 | 'field' => 'email', |
||
| 27 | 'type' => 'anomaly.field_type.email', |
||
| 28 | 'label' => 'anomaly.module.users::field.email.name', |
||
| 29 | 'required' => true, |
||
| 30 | ] |
||
| 31 | ); |
||
| 32 | } |
||
| 33 | |||
| 34 | if (!$builder->getCode()) { |
||
| 35 | $builder->addField( |
||
| 36 | [ |
||
| 37 | 'field' => 'code', |
||
| 38 | 'type' => 'anomaly.field_type.text', |
||
| 39 | 'label' => 'anomaly.module.users::field.reset_code.name', |
||
| 40 | 'required' => true, |
||
| 41 | ] |
||
| 42 | ); |
||
| 43 | } |
||
| 44 | |||
| 45 | $builder->addFields( |
||
| 46 | [ |
||
| 47 | [ |
||
| 48 | 'field' => 'password', |
||
| 49 | 'type' => 'anomaly.field_type.text', |
||
| 50 | 'label' => 'anomaly.module.users::field.password.name', |
||
| 51 | 'required' => true, |
||
| 52 | 'rules' => [ |
||
| 53 | 'confirmed' |
||
| 54 | ], |
||
| 55 | 'config' => [ |
||
| 56 | 'type' => 'password' |
||
| 57 | ] |
||
| 58 | ], |
||
| 59 | [ |
||
| 60 | 'field' => 'password_confirmation', |
||
| 61 | 'type' => 'anomaly.field_type.text', |
||
| 62 | 'label' => 'anomaly.module.users::field.confirm_password.name', |
||
| 63 | 'required' => true, |
||
| 64 | 'config' => [ |
||
| 65 | 'type' => 'password' |
||
| 66 | ], |
||
| 67 | ] |
||
| 68 | ] |
||
| 69 | ); |
||
| 70 | } |
||
| 71 | } |
||
| 72 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: