Conditions | 28 |
Paths | 288 |
Total Lines | 134 |
Code Lines | 100 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
84 | public function edit(Request $request) |
||
85 | { |
||
86 | $this->setAdminPrefs(); |
||
87 | |||
88 | $user = [ |
||
89 | 'id' => '', |
||
90 | 'username' => '', |
||
91 | 'email' => '', |
||
92 | 'password' => '', |
||
93 | 'role' => User::ROLE_USER, |
||
94 | 'notes' => '', |
||
95 | 'rate_limit' => 60, |
||
96 | ]; |
||
97 | |||
98 | $meta_title = $title = 'View User'; |
||
99 | |||
100 | // set the current action |
||
101 | $action = $request->input('action') ?? 'view'; |
||
102 | |||
103 | //get the user roles |
||
104 | $userRoles = Role::cursor()->remember(); |
||
105 | $roles = []; |
||
106 | $defaultRole = 'User'; |
||
107 | $defaultInvites = Invitation::DEFAULT_INVITES; |
||
108 | foreach ($userRoles as $r) { |
||
109 | $roles[$r->id] = $r->name; |
||
110 | if ($r->isdefault === 1) { |
||
111 | $defaultRole = $r->id; |
||
112 | $defaultInvites = $r->defaultinvites; |
||
113 | } |
||
114 | } |
||
115 | |||
116 | switch ($action) { |
||
117 | case 'add': |
||
118 | $user += [ |
||
119 | 'role' => $defaultRole, |
||
120 | 'notes' => '', |
||
121 | 'invites' => $defaultInvites, |
||
122 | 'movieview' => 0, |
||
123 | 'xxxview' => 0, |
||
124 | 'musicview' => 0, |
||
125 | 'consoleview' => 0, |
||
126 | 'gameview' => 0, |
||
127 | 'bookview' => 0, |
||
128 | ]; |
||
129 | $this->smarty->assign('user', $user); |
||
130 | break; |
||
131 | case 'submit': |
||
132 | if (empty($request->input('id'))) { |
||
133 | $invites = $defaultInvites; |
||
134 | foreach ($userRoles as $role) { |
||
135 | if ($role['id'] === $request->input('role')) { |
||
136 | $invites = $role['defaultinvites']; |
||
137 | } |
||
138 | } |
||
139 | $ret = User::signUp($request->input('username'), $request->input('password'), $request->input('email'), '', $request->input('notes'), $invites, '', true, $request->input('role'), false); |
||
140 | $this->smarty->assign('role', $request->input('role')); |
||
141 | } else { |
||
142 | $editedUser = User::find($request->input('id')); |
||
143 | $ret = User::updateUser($editedUser->id, $request->input('username'), $request->input('email'), $request->input('grabs'), $request->input('role'), $request->input('notes'), $request->input('invites'), ($request->has('movieview') ? 1 : 0), ($request->has('musicview') ? 1 : 0), ($request->has('gameview') ? 1 : 0), ($request->has('xxxview') ? 1 : 0), ($request->has('consoleview') ? 1 : 0), ($request->has('bookview') ? 1 : 0)); |
||
144 | if ($request->input('password') !== null) { |
||
145 | User::updatePassword($editedUser->id, $request->input('password')); |
||
146 | } |
||
147 | if ($request->input('rolechangedate') !== null) { |
||
148 | User::updateUserRoleChangeDate($editedUser->id, $request->input('rolechangedate')); |
||
149 | } |
||
150 | if ($request->input('role') !== null) { |
||
151 | $roleName = Role::query()->where('id', $request->input('role'))->value('name'); |
||
152 | if (($roleName === 'Disabled') && config('firewall.enabled') === true && ! \Firewall::isBlacklisted($editedUser->host)) { |
||
153 | \Firewall::blacklist($editedUser->host); |
||
154 | } |
||
155 | $editedUser->refresh(); |
||
156 | SendAccountChangedEmail::dispatch($editedUser)->onQueue('emails'); |
||
157 | } |
||
158 | } |
||
159 | |||
160 | if ($ret >= 0) { |
||
161 | return redirect('admin/user-list'); |
||
162 | } |
||
163 | |||
164 | switch ($ret) { |
||
165 | case User::ERR_SIGNUP_BADUNAME: |
||
166 | $this->smarty->assign('error', 'Bad username. Try a better one.'); |
||
167 | break; |
||
168 | case User::ERR_SIGNUP_BADPASS: |
||
169 | $this->smarty->assign('error', 'Bad password. Try a longer one.'); |
||
170 | break; |
||
171 | case User::ERR_SIGNUP_BADEMAIL: |
||
172 | $this->smarty->assign('error', 'Bad email.'); |
||
173 | break; |
||
174 | case User::ERR_SIGNUP_UNAMEINUSE: |
||
175 | $this->smarty->assign('error', 'Username in use.'); |
||
176 | break; |
||
177 | case User::ERR_SIGNUP_EMAILINUSE: |
||
178 | $this->smarty->assign('error', 'Email in use.'); |
||
179 | break; |
||
180 | default: |
||
181 | $this->smarty->assign('error', 'Unknown save error.'); |
||
182 | break; |
||
183 | } |
||
184 | $user += [ |
||
185 | 'id' => $request->input('id'), |
||
186 | 'username' => $request->input('username'), |
||
187 | 'email' => $request->input('email'), |
||
188 | 'role' => $request->input('role'), |
||
189 | 'notes' => $request->input('notes'), |
||
190 | ]; |
||
191 | $this->smarty->assign('user', $user); |
||
192 | break; |
||
193 | case 'view': |
||
194 | default: |
||
195 | if ($request->has('id')) { |
||
196 | $title = 'User Edit'; |
||
197 | $id = $request->input('id'); |
||
198 | $user = User::find($id); |
||
199 | |||
200 | $this->smarty->assign('user', $user); |
||
201 | } |
||
202 | |||
203 | break; |
||
204 | } |
||
205 | |||
206 | $this->smarty->assign('yesno_ids', [1, 0]); |
||
207 | $this->smarty->assign('yesno_names', ['Yes', 'No']); |
||
208 | |||
209 | $this->smarty->assign('role_ids', array_keys($roles)); |
||
210 | $this->smarty->assign('role_names', $roles); |
||
211 | $this->smarty->assign('user', $user); |
||
212 | |||
213 | $content = $this->smarty->fetch('user-edit.tpl'); |
||
214 | |||
215 | $this->smarty->assign(compact('title', 'meta_title', 'content')); |
||
216 | |||
217 | $this->adminrender(); |
||
218 | } |
||
274 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.