Conditions | 43 |
Paths | 466 |
Total Lines | 190 |
Code Lines | 133 |
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 | $mv = new Movie; |
||
18 | |||
19 | $action = $request->input('id') ?? ''; |
||
20 | $imdbid = $request->input('imdb') ?? ''; |
||
21 | |||
22 | if ($request->has('from')) { |
||
23 | $this->smarty->assign('from', url($request->input('from'))); |
||
24 | } else { |
||
25 | $this->smarty->assign('from', url('/mymovies')); |
||
26 | } |
||
27 | |||
28 | switch ($action) { |
||
29 | case 'delete': |
||
30 | $movie = UserMovie::getMovie($this->userdata->id, $imdbid); |
||
31 | if (! $movie) { |
||
|
|||
32 | return redirect()->to('/mymovies'); |
||
33 | } |
||
34 | UserMovie::delMovie($this->userdata->id, $imdbid); |
||
35 | if ($request->has('from')) { |
||
36 | header('Location:'.url($request->input('from'))); |
||
37 | } else { |
||
38 | return redirect()->to('/mymovies'); |
||
39 | } |
||
40 | |||
41 | break; |
||
42 | case 'add': |
||
43 | case 'doadd': |
||
44 | $movie = UserMovie::getMovie($this->userdata->id, $imdbid); |
||
45 | if ($movie) { |
||
46 | return redirect()->to('/mymovies'); |
||
47 | } |
||
48 | |||
49 | $movie = $mv->getMovieInfo($imdbid); |
||
50 | if (! $movie) { |
||
51 | return redirect()->to('/mymovies'); |
||
52 | } |
||
53 | |||
54 | if ($action === 'doadd') { |
||
55 | $category = ($request->has('category') && \is_array($request->input('category')) && ! empty($request->input('category'))) ? $request->input('category') : []; |
||
56 | UserMovie::addMovie($this->userdata->id, $imdbid, $category); |
||
57 | if ($request->has('from')) { |
||
58 | return redirect()->to($request->input('from')); |
||
59 | } |
||
60 | |||
61 | return redirect()->to('/mymovies'); |
||
62 | } |
||
63 | |||
64 | $tmpcats = Category::getChildren(Category::MOVIE_ROOT); |
||
65 | $categories = []; |
||
66 | foreach ($tmpcats as $c) { |
||
67 | // If MOVIE WEB-DL categorization is disabled, don't include it as an option |
||
68 | if ((int) $c['id'] === Category::MOVIE_WEBDL && (int) Settings::settingValue('catwebdl') === 0) { |
||
69 | continue; |
||
70 | } |
||
71 | $categories[$c['id']] = $c['title']; |
||
72 | } |
||
73 | $this->smarty->assign('type', 'add'); |
||
74 | $this->smarty->assign('cat_ids', array_keys($categories)); |
||
75 | $this->smarty->assign('cat_names', $categories); |
||
76 | $this->smarty->assign('cat_selected', []); |
||
77 | $this->smarty->assign('imdbid', $imdbid); |
||
78 | $this->smarty->assign('movie', $movie); |
||
79 | $content = $this->smarty->fetch('mymovies-add.tpl'); |
||
80 | $this->smarty->assign('content', $content); |
||
81 | $this->pagerender(); |
||
82 | break; |
||
83 | case 'edit': |
||
84 | case 'doedit': |
||
85 | $movie = UserMovie::getMovie($this->userdata->id, $imdbid); |
||
86 | |||
87 | if (! $movie) { |
||
88 | return redirect()->to('/mymovies'); |
||
89 | } |
||
90 | |||
91 | if ($action === 'doedit') { |
||
92 | $category = ($request->has('category') && \is_array($request->input('category')) && ! empty($request->input('category'))) ? $request->input('category') : []; |
||
93 | UserMovie::updateMovie($this->userdata->id, $imdbid, $category); |
||
94 | if ($request->has('from')) { |
||
95 | return redirect()->to($request->input('from')); |
||
96 | } |
||
97 | |||
98 | return redirect()->to('mymovies'); |
||
99 | } |
||
100 | |||
101 | $tmpcats = Category::getChildren(Category::MOVIE_ROOT); |
||
102 | $categories = []; |
||
103 | foreach ($tmpcats as $c) { |
||
104 | $categories[$c['id']] = $c['title']; |
||
105 | } |
||
106 | |||
107 | $this->smarty->assign('type', 'edit'); |
||
108 | $this->smarty->assign('cat_ids', array_keys($categories)); |
||
109 | $this->smarty->assign('cat_names', $categories); |
||
110 | $this->smarty->assign('cat_selected', explode('|', $movie['categories'])); |
||
111 | $this->smarty->assign('imdbid', $imdbid); |
||
112 | $this->smarty->assign('movie', $movie); |
||
113 | $content = $this->smarty->fetch('mymovies-add.tpl'); |
||
114 | $this->smarty->assign('content', $content); |
||
115 | $this->pagerender(); |
||
116 | break; |
||
117 | case 'browse': |
||
118 | |||
119 | $title = 'Browse My Movies'; |
||
120 | $meta_title = 'My Movies'; |
||
121 | $meta_keywords = 'search,add,to,cart,nzb,description,details'; |
||
122 | $meta_description = 'Browse Your Movies'; |
||
123 | |||
124 | $page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1; |
||
125 | |||
126 | $offset = ($page - 1) * config('nntmux.items_per_cover_page'); |
||
127 | |||
128 | $movies = UserMovie::getMovies($this->userdata->id); |
||
129 | $categories = $movie = []; |
||
130 | foreach ($movies as $moviek => $movie) { |
||
131 | $showcats = explode('|', $movie['categories']); |
||
132 | if (\is_array($showcats) && \count($showcats) > 0) { |
||
133 | $catarr = []; |
||
134 | foreach ($showcats as $scat) { |
||
135 | if (! empty($scat)) { |
||
136 | $catarr[] = $categories[$scat]; |
||
137 | } |
||
138 | } |
||
139 | $movie['categoryNames'] = implode(', ', $catarr); |
||
140 | } else { |
||
141 | $movie['categoryNames'] = ''; |
||
142 | } |
||
143 | } |
||
144 | |||
145 | $ordering = (new Releases)->getBrowseOrdering(); |
||
146 | |||
147 | $page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1; |
||
148 | |||
149 | $results = $mv->getMovieRange($page, $movie['categoryNames'], $offset, config('nntmux.items_per_cover_page'), $ordering, -1, $this->userdata->categoryexclusions); |
||
150 | |||
151 | $this->smarty->assign('covgroup', ''); |
||
152 | |||
153 | foreach ($ordering as $ordertype) { |
||
154 | $this->smarty->assign('orderby'.$ordertype, url('/mymovies/browse?ob='.$ordertype.'&offset=0')); |
||
155 | } |
||
156 | |||
157 | $this->smarty->assign('lastvisit', $this->userdata->lastlogin); |
||
158 | |||
159 | $this->smarty->assign('results', $results); |
||
160 | |||
161 | $this->smarty->assign('movies', true); |
||
162 | |||
163 | $content = $this->smarty->fetch('browse.tpl'); |
||
164 | $this->smarty->assign(compact('content', 'title', 'meta_title', 'meta_keywords', 'meta_description')); |
||
165 | $this->pagerender(); |
||
166 | break; |
||
167 | default: |
||
168 | |||
169 | $title = 'My Movies'; |
||
170 | $meta_title = 'My Movies'; |
||
171 | $meta_keywords = 'search,add,to,cart,nzb,description,details'; |
||
172 | $meta_description = 'Manage Your Movies'; |
||
173 | |||
174 | $tmpcats = Category::getChildren(Category::MOVIE_ROOT); |
||
175 | $categories = []; |
||
176 | foreach ($tmpcats as $c) { |
||
177 | $categories[$c['id']] = $c['title']; |
||
178 | } |
||
179 | |||
180 | $movies = UserMovie::getMovies($this->userdata->id); |
||
181 | $results = []; |
||
182 | foreach ($movies as $moviek => $movie) { |
||
183 | $showcats = explode('|', $movie['categories']); |
||
184 | if (\is_array($showcats) && \count($showcats) > 0) { |
||
185 | $catarr = []; |
||
186 | foreach ($showcats as $scat) { |
||
187 | if (! empty($scat)) { |
||
188 | $catarr[] = $categories[$scat]; |
||
189 | } |
||
190 | } |
||
191 | $movie['categoryNames'] = implode(', ', $catarr); |
||
192 | } else { |
||
193 | $movie['categoryNames'] = ''; |
||
194 | } |
||
195 | |||
196 | $results[$moviek] = $movie; |
||
197 | } |
||
198 | $this->smarty->assign('movies', $results); |
||
199 | |||
200 | $content = $this->smarty->fetch('mymovies.tpl'); |
||
201 | $this->smarty->assign(compact('content', 'title', 'meta_title', 'meta_keywords', 'meta_description')); |
||
202 | $this->pagerender(); |
||
203 | break; |
||
204 | } |
||
207 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.