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