| Conditions | 49 |
| Paths | > 20000 |
| Total Lines | 116 |
| Code Lines | 78 |
| 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 |
||
| 122 | public function edit(Request $request): void |
||
| 123 | { |
||
| 124 | $this->setAdminPrefs(); |
||
| 125 | |||
| 126 | $meta_title = $title = 'User Roles'; |
||
| 127 | |||
| 128 | // Get the user roles. |
||
| 129 | $userRoles = Role::cursor()->remember(); |
||
| 130 | $roles = []; |
||
| 131 | foreach ($userRoles as $userRole) { |
||
| 132 | $roles[$userRole->id] = $userRole->name; |
||
| 133 | } |
||
| 134 | |||
| 135 | switch ($request->input('action') ?? 'view') { |
||
| 136 | case 'submit': |
||
| 137 | $meta_title = $title = 'Update User Role'; |
||
| 138 | $role = Role::find($request->input('id')); |
||
| 139 | $role->update([ |
||
| 140 | 'name' => $request->input('name'), |
||
| 141 | 'apirequests' => $request->input('apirequests'), |
||
| 142 | 'downloadrequests' => $request->input('downloadrequests'), |
||
| 143 | 'defaultinvites' => $request->input('defaultinvites'), |
||
| 144 | 'isdefault' => $request->input('isdefault'), |
||
| 145 | 'donation' => $request->input('donation'), |
||
| 146 | 'addyears' => $request->input('addyears'), |
||
| 147 | 'rate_limit' => $request->input('rate_limit'), |
||
| 148 | ]); |
||
| 149 | |||
| 150 | if ((int) $request->input('canpreview') === 1 && $role->hasPermissionTo('preview') === false) { |
||
| 151 | $role->givePermissionTo('preview'); |
||
| 152 | } elseif ((int) $request->input('canpreview') === 0 && $role->hasPermissionTo('preview') === true) { |
||
| 153 | $role->revokePermissionTo('preview'); |
||
| 154 | } |
||
| 155 | |||
| 156 | if ((int) $request->input('hideads') === 1 && $role->hasPermissionTo('hideads') === false) { |
||
| 157 | $role->givePermissionTo('hideads'); |
||
| 158 | } elseif ((int) $request->input('hideads') === 0 && $role->hasPermissionTo('hideads') === true) { |
||
| 159 | $role->revokePermissionTo('hideads'); |
||
| 160 | } |
||
| 161 | |||
| 162 | if ((int) $request->input('editrelease') === 1 && $role->hasPermissionTo('edit release') === false) { |
||
| 163 | $role->givePermissionTo('edit release'); |
||
| 164 | } elseif ((int) $request->input('editrelease') === 0 && $role->hasPermissionTo('edit release') === true) { |
||
| 165 | $role->revokePermissionTo('edit release'); |
||
| 166 | } |
||
| 167 | |||
| 168 | if ((int) $request->input('viewconsole') === 1 && $role->hasPermissionTo('view console') === false) { |
||
| 169 | $role->givePermissionTo('view console'); |
||
| 170 | } elseif ((int) $request->input('viewconsole') === 0 && $role->hasPermissionTo('view console') === true) { |
||
| 171 | $role->revokePermissionTo('view console'); |
||
| 172 | } |
||
| 173 | |||
| 174 | if ((int) $request->input('viewmovies') === 1 && $role->hasPermissionTo('view movies') === false) { |
||
| 175 | $role->givePermissionTo('view movies'); |
||
| 176 | } elseif ((int) $request->input('viewmovies') === 0 && $role->hasPermissionTo('view movies') === true) { |
||
| 177 | $role->revokePermissionTo('view movies'); |
||
| 178 | } |
||
| 179 | |||
| 180 | if ((int) $request->input('viewaudio') === 1 && $role->hasPermissionTo('view audio') === false) { |
||
| 181 | $role->givePermissionTo('view audio'); |
||
| 182 | } elseif ((int) $request->input('viewaudio') === 0 && $role->hasPermissionTo('view audio') === true) { |
||
| 183 | $role->revokePermissionTo('view audio'); |
||
| 184 | } |
||
| 185 | |||
| 186 | if ((int) $request->input('viewpc') === 1 && $role->hasPermissionTo('view pc') === false) { |
||
| 187 | $role->givePermissionTo('view pc'); |
||
| 188 | } elseif ((int) $request->input('viewpc') === 0 && $role->hasPermissionTo('view pc') === true) { |
||
| 189 | $role->revokePermissionTo('view pc'); |
||
| 190 | } |
||
| 191 | |||
| 192 | if ((int) $request->input('viewtv') === 1 && $role->hasPermissionTo('view tv') === false) { |
||
| 193 | $role->givePermissionTo('view tv'); |
||
| 194 | } elseif ((int) $request->input('viewtv') === 0 && $role->hasPermissionTo('view tv') === true) { |
||
| 195 | $role->revokePermissionTo('view tv'); |
||
| 196 | } |
||
| 197 | |||
| 198 | if ((int) $request->input('viewadult') === 1 && $role->hasPermissionTo('view adult') === false) { |
||
| 199 | $role->givePermissionTo('view adult'); |
||
| 200 | } elseif ((int) $request->input('viewadult') === 0 && $role->hasPermissionTo('view adult') === true) { |
||
| 201 | $role->revokePermissionTo('view adult'); |
||
| 202 | } |
||
| 203 | |||
| 204 | if ((int) $request->input('viewbooks') === 1 && $role->hasPermissionTo('view books') === false) { |
||
| 205 | $role->givePermissionTo('view books'); |
||
| 206 | } elseif ((int) $request->input('viewbooks') === 0 && $role->hasPermissionTo('view books') === true) { |
||
| 207 | $role->revokePermissionTo('view books'); |
||
| 208 | } |
||
| 209 | |||
| 210 | if ((int) $request->input('viewother') === 1 && $role->hasPermissionTo('view other') === false) { |
||
| 211 | $role->givePermissionTo('view other'); |
||
| 212 | } elseif ((int) $request->input('viewother') === 0 && $role->hasPermissionTo('view other') === true) { |
||
| 213 | $role->revokePermissionTo('view other'); |
||
| 214 | } |
||
| 215 | |||
| 216 | $this->smarty->assign('role', $role); |
||
| 217 | redirect()->to('admin/role-list')->sendHeaders(); |
||
| 218 | break; |
||
| 219 | |||
| 220 | case 'view': |
||
| 221 | default: |
||
| 222 | if ($request->has('id')) { |
||
| 223 | $meta_title = $title = 'User Roles Edit'; |
||
| 224 | $role = Role::findById($request->input('id')); |
||
| 225 | $this->smarty->assign('role', $role); |
||
| 226 | } |
||
| 227 | break; |
||
| 228 | } |
||
| 229 | |||
| 230 | $this->smarty->assign('yesno_ids', [1, 0]); |
||
| 231 | $this->smarty->assign('yesno_names', ['Yes', 'No']); |
||
| 232 | |||
| 233 | $content = $this->smarty->fetch('role-edit.tpl'); |
||
| 234 | |||
| 235 | $this->smarty->assign(compact('title', 'meta_title', 'content')); |
||
| 236 | |||
| 237 | $this->adminrender(); |
||
| 238 | } |
||
| 254 |
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.