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