| Conditions | 9 |
| Paths | 13 |
| Total Lines | 60 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 26 | public function showLinkRequestForm(Request $request): void |
||
| 27 | { |
||
| 28 | $sent = ''; |
||
| 29 | $email = $request->input('email') ?? ''; |
||
| 30 | $rssToken = $request->input('apikey') ?? ''; |
||
| 31 | if (empty($email) && empty($rssToken)) { |
||
| 32 | app('smarty.view')->assign('error', 'Missing parameter (email and/or apikey) to send password reset'); |
||
| 33 | } else { |
||
| 34 | if (config('captcha.enabled') === true && (! empty(config('captcha.secret')) && ! empty(config('captcha.sitekey')))) { |
||
| 35 | $validate = Validator::make($request->all(), [ |
||
| 36 | 'g-recaptcha-response' => 'required|captcha', |
||
| 37 | ]); |
||
| 38 | if ($validate->fails()) { |
||
| 39 | app('smarty.view')->assign('error', 'Captcha validation failed.'); |
||
| 40 | } |
||
| 41 | } |
||
| 42 | // |
||
| 43 | // Check users exists and send an email |
||
| 44 | // |
||
| 45 | $ret = ! empty($rssToken) ? User::getByRssToken($rssToken) : User::getByEmail($email); |
||
| 46 | if ($ret === null) { |
||
| 47 | app('smarty.view')->assign('error', 'The email or apikey are not recognised.'); |
||
| 48 | } else { |
||
| 49 | // |
||
| 50 | // Generate a forgottenpassword guid, store it in the user table |
||
| 51 | // |
||
| 52 | $guid = Str::random(32); |
||
| 53 | User::updatePassResetGuid($ret['id'], $guid); |
||
| 54 | // |
||
| 55 | // Send the email |
||
| 56 | // |
||
| 57 | $resetLink = url('/').'/resetpassword?guid='.$guid; |
||
| 58 | SendPasswordForgottenEmail::dispatch($ret, $resetLink); |
||
| 59 | app('smarty.view')->assign('success', 'Password reset email has been sent!'); |
||
| 60 | } |
||
| 61 | $sent = true; |
||
| 62 | } |
||
| 63 | |||
| 64 | $theme = 'Gentele'; |
||
| 65 | |||
| 66 | $title = 'Forgotten Password'; |
||
| 67 | $meta_title = 'Forgotten Password'; |
||
| 68 | $meta_keywords = 'forgotten,password,signup,registration'; |
||
| 69 | $meta_description = 'Forgotten Password'; |
||
| 70 | |||
| 71 | $content = app('smarty.view')->fetch($theme.'/forgottenpassword.tpl'); |
||
| 72 | |||
| 73 | app('smarty.view')->assign( |
||
| 74 | [ |
||
| 75 | 'content' => $content, |
||
| 76 | 'title' => $title, |
||
| 77 | 'meta_title' => $meta_title, |
||
| 78 | 'meta_keywords' => $meta_keywords, |
||
| 79 | 'meta_description' => $meta_description, |
||
| 80 | 'email' => $email, |
||
| 81 | 'apikey' => $rssToken, |
||
| 82 | 'sent' => $sent, |
||
| 83 | ] |
||
| 84 | ); |
||
| 85 | app('smarty.view')->display($theme.'/basepage.tpl'); |
||
| 86 | } |
||
| 88 |