| Conditions | 12 |
| Paths | 11 |
| Total Lines | 53 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 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 |
||
| 42 | static function user_registration () { |
||
| 43 | $Config = Config::instance(); |
||
| 44 | $L = Language::instance(); |
||
| 45 | $Page = Page::instance(); |
||
| 46 | $User = User::instance(); |
||
| 47 | if (!isset($_POST['email'])) { |
||
| 48 | throw new ExitException(400); |
||
| 49 | } elseif (!$User->guest()) { |
||
| 50 | $Page->json('reload'); |
||
| 51 | return; |
||
| 52 | } elseif (!$Config->core['allow_user_registration']) { |
||
| 53 | throw new ExitException($L->registration_prohibited, 403); |
||
| 54 | } elseif (empty($_POST['email'])) { |
||
| 55 | throw new ExitException($L->please_type_your_email, 400); |
||
| 56 | } |
||
| 57 | $_POST['email'] = mb_strtolower($_POST['email']); |
||
| 58 | $result = $User->registration($_POST['email']); |
||
| 59 | if ($result === false) { |
||
| 60 | throw new ExitException($L->please_type_correct_email, 400); |
||
| 61 | } elseif ($result == 'error') { |
||
| 62 | throw new ExitException($L->reg_server_error, 500); |
||
| 63 | } elseif ($result == 'exists') { |
||
| 64 | throw new ExitException($L->reg_error_exists, 400); |
||
| 65 | } |
||
| 66 | $confirm = $result['reg_key'] !== true; |
||
| 67 | if ($confirm) { |
||
| 68 | $body = $L->reg_need_confirmation_mail_body( |
||
|
1 ignored issue
–
show
|
|||
| 69 | strstr($_POST['email'], '@', true), |
||
| 70 | get_core_ml_text('name'), |
||
| 71 | $Config->core_url()."/profile/registration_confirmation/$result[reg_key]", |
||
| 72 | $L->time($Config->core['registration_confirmation_time'], 'd') |
||
| 73 | ); |
||
| 74 | } else { |
||
| 75 | $body = $L->reg_success_mail_body( |
||
|
1 ignored issue
–
show
|
|||
| 76 | strstr($_POST['email'], '@', true), |
||
| 77 | get_core_ml_text('name'), |
||
| 78 | $Config->core_url().'/profile/settings', |
||
| 79 | $User->get('login', $result['id']), |
||
| 80 | $result['password'] |
||
| 81 | ); |
||
| 82 | } |
||
| 83 | if (Mail::instance()->send_to( |
||
| 84 | $_POST['email'], |
||
| 85 | $L->{$confirm ? 'reg_need_confirmation_mail' : 'reg_success_mail'}(get_core_ml_text('name')), |
||
| 86 | $body |
||
| 87 | ) |
||
| 88 | ) { |
||
| 89 | $Page->json($confirm ? 'reg_confirmation' : 'reg_success'); |
||
| 90 | } else { |
||
| 91 | $User->registration_cancel(); |
||
| 92 | throw new ExitException($L->sending_reg_mail_error, 500); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | static function user_restore_password () { |
||
| 186 |
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: