Conditions | 6 |
Paths | 8 |
Total Lines | 56 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
44 | public function reset(Request $request): void |
||
45 | { |
||
46 | $error = ''; |
||
47 | $confirmed = ''; |
||
48 | $onscreen = ''; |
||
49 | if ($request->missing('guid')) { |
||
50 | $error = 'No reset code provided.'; |
||
51 | } |
||
52 | |||
53 | if ($error === '') { |
||
54 | $ret = User::getByPassResetGuid($request->input('guid')); |
||
55 | if ($ret === null) { |
||
56 | $error = 'Bad reset code provided.'; |
||
57 | } else { |
||
58 | // Check if user is soft deleted |
||
59 | $user = User::withTrashed()->find($ret['id']); |
||
60 | if ($user && $user->trashed()) { |
||
61 | $error = 'This account has been deactivated.'; |
||
62 | } else { |
||
63 | // |
||
64 | // reset the password, inform the user, send out the email |
||
65 | // |
||
66 | User::updatePassResetGuid($ret['id'], ''); |
||
67 | $newpass = User::generatePassword(); |
||
68 | User::updatePassword($ret['id'], $newpass); |
||
69 | |||
70 | $onscreen = 'Your password has been reset to <strong>'.$newpass.'</strong> and sent to your e-mail address.'; |
||
71 | SendPasswordResetEmail::dispatch($ret, $newpass); |
||
72 | $confirmed = true; |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | |||
77 | $theme = 'Gentele'; |
||
78 | |||
79 | $title = 'Forgotten Password'; |
||
80 | $meta_title = 'Forgotten Password'; |
||
81 | $meta_keywords = 'forgotten,password,signup,registration'; |
||
82 | $meta_description = 'Forgotten Password'; |
||
83 | |||
84 | $content = app('smarty.view')->fetch($theme.'/forgottenpassword.tpl'); |
||
85 | |||
86 | app('smarty.view')->assign( |
||
87 | [ |
||
88 | 'content' => $content, |
||
89 | 'title' => $title, |
||
90 | 'meta_title' => $meta_title, |
||
91 | 'meta_keywords' => $meta_keywords, |
||
92 | 'meta_description' => $meta_description, |
||
93 | 'email' => $ret['email'] ?? '', |
||
94 | 'confirmed' => $confirmed, |
||
95 | 'error' => $error, |
||
96 | 'notice' => $onscreen, |
||
97 | ] |
||
98 | ); |
||
99 | app('smarty.view')->display($theme.'/basepage.tpl'); |
||
100 | } |
||
102 |