| Conditions | 14 |
| Paths | 2050 |
| Total Lines | 77 |
| Code Lines | 47 |
| 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 |
||
| 35 | public function create(Request $request) |
||
| 36 | { |
||
| 37 | $this->setAdminPrefs(); |
||
| 38 | |||
| 39 | switch ($request->input('action') ?? 'view') { |
||
| 40 | case 'submit': |
||
| 41 | $meta_title = $title = 'Add User Role'; |
||
| 42 | $role = Role::create([ |
||
| 43 | 'name' => $request->input('name'), |
||
| 44 | 'apirequests' => $request->input('apirequests'), |
||
| 45 | 'downloadrequests' => $request->input('downloadrequests'), |
||
| 46 | 'defaultinvites' => $request->input('defaultinvites'), |
||
| 47 | 'donation' => $request->input('donation') ?? 0, |
||
| 48 | 'addyears' => $request->input('addyears') ?? 0, |
||
| 49 | 'rate_limit' => $request->input('rate_limit'), |
||
| 50 | ]); |
||
| 51 | if ((int) $request->input('canpreview') === 1) { |
||
| 52 | $role->givePermissionTo('preview'); |
||
| 53 | } |
||
| 54 | |||
| 55 | if ((int) $request->input('hideads') === 1) { |
||
| 56 | $role->givePermissionTo('hideads'); |
||
| 57 | } |
||
| 58 | |||
| 59 | if ((int) $request->input('editrelease') === 1) { |
||
| 60 | $role->givePermissionTo('edit release'); |
||
| 61 | } |
||
| 62 | |||
| 63 | if ((int) $request->input('viewconsole') === 1) { |
||
| 64 | $role->givePermissionTo('view console'); |
||
| 65 | } |
||
| 66 | |||
| 67 | if ((int) $request->input('viewmovies') === 1) { |
||
| 68 | $role->givePermissionTo('view movies'); |
||
| 69 | } |
||
| 70 | |||
| 71 | if ((int) $request->input('viewaudio') === 1) { |
||
| 72 | $role->givePermissionTo('view audio'); |
||
| 73 | } |
||
| 74 | |||
| 75 | if ((int) $request->input('viewpc') === 1) { |
||
| 76 | $role->givePermissionTo('view pc'); |
||
| 77 | } |
||
| 78 | |||
| 79 | if ((int) $request->input('viewtv') === 1) { |
||
| 80 | $role->givePermissionTo('view tv'); |
||
| 81 | } |
||
| 82 | |||
| 83 | if ((int) $request->input('viewadult') === 1) { |
||
| 84 | $role->givePermissionTo('view adult'); |
||
| 85 | } |
||
| 86 | |||
| 87 | if ((int) $request->input('viewbooks') === 1) { |
||
| 88 | $role->givePermissionTo('view books'); |
||
| 89 | } |
||
| 90 | |||
| 91 | if ((int) $request->input('viewother') === 1) { |
||
| 92 | $role->givePermissionTo('view other'); |
||
| 93 | } |
||
| 94 | |||
| 95 | return redirect()->to('admin/role-list'); |
||
| 96 | case 'view': |
||
| 97 | default: |
||
| 98 | $meta_title = $title = 'Add User Role'; |
||
| 99 | $role = []; |
||
| 100 | break; |
||
| 101 | } |
||
| 102 | |||
| 103 | $this->viewData = array_merge($this->viewData, [ |
||
| 104 | 'yesno_ids' => [1, 0], |
||
| 105 | 'yesno_names' => ['Yes', 'No'], |
||
| 106 | 'title' => $title, |
||
| 107 | 'meta_title' => $meta_title, |
||
| 108 | 'role' => $role, |
||
| 109 | ]); |
||
| 110 | |||
| 111 | return view('admin.roles.add', $this->viewData); |
||
| 112 | } |
||
| 243 |