| Conditions | 33 |
| Paths | 142 |
| Total Lines | 143 |
| Code Lines | 96 |
| 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 |
||
| 14 | public function show(Request $request) |
||
| 15 | { |
||
| 16 | $action = $request->input('action') ?? ''; |
||
| 17 | $videoId = $request->input('id') ?? ''; |
||
| 18 | |||
| 19 | if ($request->has('from')) { |
||
| 20 | $this->viewData['from'] = url($request->input('from')); |
||
| 21 | } else { |
||
| 22 | $this->viewData['from'] = url('/myshows'); |
||
| 23 | } |
||
| 24 | |||
| 25 | switch ($action) { |
||
| 26 | case 'delete': |
||
| 27 | $show = UserSerie::getShow($this->userdata->id, $videoId); |
||
| 28 | if (! $show) { |
||
| 29 | return redirect()->back(); |
||
| 30 | } |
||
| 31 | |||
| 32 | UserSerie::delShow($this->userdata->id, $videoId); |
||
| 33 | if ($request->has('from')) { |
||
| 34 | header('Location:'.url($request->input('from'))); |
||
|
|
|||
| 35 | } else { |
||
| 36 | return redirect()->to('myshows'); |
||
| 37 | } |
||
| 38 | |||
| 39 | break; |
||
| 40 | case 'add': |
||
| 41 | case 'doadd': |
||
| 42 | $show = UserSerie::getShow($this->userdata->id, $videoId); |
||
| 43 | if ($show) { |
||
| 44 | return redirect()->to('myshows'); |
||
| 45 | } |
||
| 46 | |||
| 47 | $show = Video::getByVideoID($videoId); |
||
| 48 | if (! $show) { |
||
| 49 | return redirect()->to('myshows'); |
||
| 50 | } |
||
| 51 | |||
| 52 | if ($action === 'doadd') { |
||
| 53 | $category = ($request->has('category') && \is_array($request->input('category')) && ! empty($request->input('category'))) ? $request->input('category') : []; |
||
| 54 | UserSerie::addShow($this->userdata->id, $videoId, $category); |
||
| 55 | if ($request->has('from')) { |
||
| 56 | return redirect()->to($request->input('from')); |
||
| 57 | } |
||
| 58 | |||
| 59 | return redirect()->to('myshows'); |
||
| 60 | } |
||
| 61 | |||
| 62 | $tmpcats = Category::getChildren(Category::TV_ROOT); |
||
| 63 | $categories = []; |
||
| 64 | foreach ($tmpcats as $c) { |
||
| 65 | // If TV WEB-DL categorization is disabled, don't include it as an option |
||
| 66 | if ((int) $c['id'] === Category::TV_WEBDL && (int) Settings::settingValue('catwebdl') === 0) { |
||
| 67 | continue; |
||
| 68 | } |
||
| 69 | $categories[$c['id']] = $c['title']; |
||
| 70 | } |
||
| 71 | $this->viewData['type'] = 'add'; |
||
| 72 | $this->viewData['cat_ids'] = array_keys($categories); |
||
| 73 | $this->viewData['cat_names'] = $categories; |
||
| 74 | $this->viewData['cat_selected'] = []; |
||
| 75 | $this->viewData['video'] = $videoId; |
||
| 76 | $this->viewData['show'] = $show; |
||
| 77 | $this->viewData['content'] = view('myshows.add', $this->viewData)->render(); |
||
| 78 | |||
| 79 | return $this->pagerender(); |
||
| 80 | |||
| 81 | case 'edit': |
||
| 82 | case 'doedit': |
||
| 83 | $show = UserSerie::getShow($this->userdata->id, $videoId); |
||
| 84 | |||
| 85 | if (! $show) { |
||
| 86 | return redirect()->to('myshows'); |
||
| 87 | } |
||
| 88 | |||
| 89 | if ($action === 'doedit') { |
||
| 90 | $category = ($request->has('category') && \is_array($request->input('category')) && ! empty($request->input('category'))) ? $request->input('category') : []; |
||
| 91 | UserSerie::updateShow($this->userdata->id, $videoId, $category); |
||
| 92 | if ($request->has('from')) { |
||
| 93 | return redirect()->to($request->input('from')); |
||
| 94 | } |
||
| 95 | |||
| 96 | return redirect()->to('myshows'); |
||
| 97 | } |
||
| 98 | |||
| 99 | $tmpcats = Category::getChildren(Category::TV_ROOT); |
||
| 100 | $categories = []; |
||
| 101 | foreach ($tmpcats as $c) { |
||
| 102 | $categories[$c['id']] = $c['title']; |
||
| 103 | } |
||
| 104 | |||
| 105 | $this->viewData['type'] = 'edit'; |
||
| 106 | $this->viewData['cat_ids'] = array_keys($categories); |
||
| 107 | $this->viewData['cat_names'] = $categories; |
||
| 108 | $this->viewData['cat_selected'] = explode('|', $show['categories']); |
||
| 109 | $this->viewData['video'] = $videoId; |
||
| 110 | $this->viewData['show'] = $show; |
||
| 111 | $this->viewData['content'] = view('myshows.add', $this->viewData)->render(); |
||
| 112 | |||
| 113 | return $this->pagerender(); |
||
| 114 | |||
| 115 | default: |
||
| 116 | |||
| 117 | $title = 'My Shows'; |
||
| 118 | $meta_title = 'My Shows'; |
||
| 119 | $meta_keywords = 'search,add,to,cart,nzb,description,details'; |
||
| 120 | $meta_description = 'Manage Your Shows'; |
||
| 121 | |||
| 122 | $tmpcats = Category::getChildren(Category::TV_ROOT); |
||
| 123 | $categories = []; |
||
| 124 | foreach ($tmpcats as $c) { |
||
| 125 | $categories[$c['id']] = $c['title']; |
||
| 126 | } |
||
| 127 | |||
| 128 | $shows = UserSerie::getShows($this->userdata->id); |
||
| 129 | $results = []; |
||
| 130 | $catArr = []; |
||
| 131 | if ($shows !== null) { |
||
| 132 | foreach ($shows as $showk => $show) { |
||
| 133 | $showcats = explode('|', $show['categories']); |
||
| 134 | if (\is_array($showcats) && ! empty($showcats)) { |
||
| 135 | foreach ($showcats as $scat) { |
||
| 136 | if (! empty($scat)) { |
||
| 137 | $catArr[] = $categories[$scat]; |
||
| 138 | } |
||
| 139 | } |
||
| 140 | $show['categoryNames'] = implode(', ', $catArr); |
||
| 141 | } else { |
||
| 142 | $show['categoryNames'] = ''; |
||
| 143 | } |
||
| 144 | |||
| 145 | $results[$showk] = $show; |
||
| 146 | } |
||
| 147 | } |
||
| 148 | $this->viewData['shows'] = $results; |
||
| 149 | $this->viewData['content'] = view('myshows.index', $this->viewData)->render(); |
||
| 150 | $this->viewData = array_merge($this->viewData, compact('title', 'meta_title', 'meta_keywords', 'meta_description')); |
||
| 151 | |||
| 152 | return $this->pagerender(); |
||
| 153 | } |
||
| 154 | |||
| 155 | // Fallback return in case no case matches |
||
| 156 | return redirect()->to('/myshows'); |
||
| 157 | } |
||
| 198 |