| Conditions | 10 |
| Paths | 12 |
| Total Lines | 56 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 2 | 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 |
||
| 56 | public function actionSignup() |
||
| 57 | { |
||
| 58 | if (App::$User->isAuth()) { // always auth? prevent any actions |
||
| 59 | throw new ForbiddenException(); |
||
| 60 | } |
||
| 61 | |||
| 62 | // load configs |
||
| 63 | $configs = $this->getConfigs(); |
||
| 64 | |||
| 65 | // init register model |
||
| 66 | $registerForm = new FormRegister($configs['captchaOnRegister'] === 1); |
||
| 67 | |||
| 68 | // registration based on invite. Check conditions. |
||
| 69 | if ($configs['registrationType'] === 0) { |
||
| 70 | // get token and email |
||
| 71 | $inviteToken = App::$Request->query->get('token'); |
||
| 72 | $inviteEmail = App::$Request->query->get('email'); |
||
| 73 | // data sounds like a invalid? |
||
| 74 | if (Str::length($inviteToken) < 32 || !Str::isEmail($inviteEmail)) { |
||
| 75 | throw new ForbiddenException(__('Registration allowed only if you have invite!')); |
||
| 76 | } |
||
| 77 | // remove oldest data |
||
| 78 | Invite::clean(); |
||
| 79 | // try to find token |
||
| 80 | $find = Invite::where('token', '=', $inviteToken) |
||
| 81 | ->where('email', '=', $inviteEmail)->count(); |
||
| 82 | |||
| 83 | // token not foud? invalid invite key |
||
| 84 | if ($find !== 1) { |
||
| 85 | throw new ForbiddenException(__('Your invite token is invalid! Contact with administrator')); |
||
| 86 | } |
||
| 87 | // notify the invite token is accepted |
||
| 88 | if (!$registerForm->send()) { |
||
| 89 | App::$Session->getFlashBag()->add('success', __('Invite was accepted! Continue registration')); |
||
| 90 | } |
||
| 91 | |||
| 92 | // set email from token data |
||
| 93 | $registerForm->email = $inviteEmail; |
||
| 94 | } |
||
| 95 | |||
| 96 | // if register data is send and valid |
||
| 97 | if ($registerForm->send() && $registerForm->validate()) { |
||
| 98 | if ($registerForm->tryRegister($configs['registrationType'] === 1)) { |
||
| 99 | App::$Session->getFlashBag()->add('success', __('Your account is registered. You must confirm account via email')); |
||
| 100 | } else { |
||
| 101 | App::$Session->getFlashBag()->add('error', __('Login or email is always used on website')); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | // render view |
||
| 106 | $this->response = App::$View->render('signup', [ |
||
| 107 | 'model' => $registerForm->export(), |
||
| 108 | 'config' => $configs, |
||
| 109 | 'useCaptcha' => $configs['captchaOnRegister'] === 1 |
||
| 110 | ]); |
||
| 111 | } |
||
| 112 | |||
| 225 | } |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: