| Total Complexity | 40 |
| Total Lines | 199 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like MovieController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use MovieController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 10 | class MovieController extends BasePageController |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @param \Illuminate\Http\Request $request |
||
| 14 | * |
||
| 15 | * @return \Illuminate\Http\JsonResponse |
||
| 16 | * @throws \Exception |
||
| 17 | */ |
||
| 18 | public function showMovie(Request $request) |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param \Illuminate\Http\Request $request |
||
| 55 | * @param string $id |
||
| 56 | * |
||
| 57 | * @throws \Exception |
||
| 58 | */ |
||
| 59 | public function showMovies(Request $request, $id = '') |
||
| 60 | { |
||
| 61 | $this->setPrefs(); |
||
| 62 | $movie = new Movie(['Settings' => $this->settings]); |
||
| 63 | |||
| 64 | $moviecats = Category::getChildren(Category::MOVIE_ROOT); |
||
| 65 | $mtmp = []; |
||
| 66 | foreach ($moviecats as $mcat) { |
||
| 67 | $mtmp[] = |
||
| 68 | [ |
||
| 69 | 'id' => $mcat->id, |
||
| 70 | 'title' => $mcat->title, |
||
| 71 | ]; |
||
| 72 | } |
||
| 73 | |||
| 74 | $category = $request->has('imdb') ? -1 : ($request->has('t') ? $request->input('t') : Category::MOVIE_ROOT); |
||
| 75 | if ($id && \in_array($id, Arr::pluck($mtmp, 'title'), false)) { |
||
| 76 | $cat = Category::query() |
||
| 77 | ->where(['title'=> $id, 'root_categories_id' => Category::MOVIE_ROOT]) |
||
| 78 | ->first(['id']); |
||
| 79 | $category = $cat !== null ? $cat['id'] : Category::MOVIE_ROOT; |
||
| 80 | } |
||
| 81 | |||
| 82 | $this->smarty->assign('cpapi', $this->userdata->cp_api); |
||
| 83 | $this->smarty->assign('cpurl', $this->userdata->cp_url); |
||
| 84 | |||
| 85 | $catarray = []; |
||
| 86 | if ((int) $category !== -1) { |
||
| 87 | $catarray[] = $category; |
||
| 88 | } |
||
| 89 | |||
| 90 | $this->smarty->assign('catlist', $mtmp); |
||
| 91 | $this->smarty->assign('category', $category); |
||
| 92 | $this->smarty->assign('categorytitle', $id); |
||
| 93 | |||
| 94 | $page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1; |
||
| 95 | $offset = ($page - 1) * config('nntmux.items_per_cover_page'); |
||
| 96 | |||
| 97 | $ordering = $movie->getMovieOrdering(); |
||
| 98 | $orderby = request()->has('ob') && \in_array(request()->input('ob'), $ordering, false) ? request()->input('ob') : ''; |
||
| 99 | |||
| 100 | $movies = []; |
||
| 101 | $rslt = $movie->getMovieRange($page, $catarray, $offset, config('nntmux.items_per_cover_page'), $orderby, -1, $this->userdata->categoryexclusions); |
||
| 102 | $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_cover_page'), $page, $request->url(), $request->query()); |
||
| 103 | |||
| 104 | foreach ($results as $result) { |
||
| 105 | $result->genre = makeFieldLinks($result, 'genre', 'movies'); |
||
| 106 | $result->actors = makeFieldLinks($result, 'actors', 'movies'); |
||
| 107 | $result->director = makeFieldLinks($result, 'director', 'movies'); |
||
| 108 | $result->languages = explode(', ', $result->language); |
||
| 109 | |||
| 110 | $movies[] = $result; |
||
| 111 | } |
||
| 112 | |||
| 113 | $title = ($request->has('title') && ! empty($request->input('title'))) ? stripslashes($request->input('title')) : ''; |
||
| 114 | $this->smarty->assign('title', $title); |
||
| 115 | |||
| 116 | $actors = ($request->has('actors') && ! empty($request->input('actors'))) ? stripslashes($request->input('actors')) : ''; |
||
| 117 | $this->smarty->assign('actors', $actors); |
||
| 118 | |||
| 119 | $director = ($request->has('director') && ! empty($request->input('director'))) ? stripslashes($request->input('director')) : ''; |
||
| 120 | $this->smarty->assign('director', $director); |
||
| 121 | |||
| 122 | $ratings = range(1, 9); |
||
| 123 | $rating = ($request->has('rating') && \in_array($request->input('rating'), $ratings, false)) ? $request->input('rating') : ''; |
||
| 124 | $this->smarty->assign('ratings', $ratings); |
||
| 125 | $this->smarty->assign('rating', $rating); |
||
| 126 | |||
| 127 | $genres = $movie->getGenres(); |
||
| 128 | $genre = ($request->has('genre') && \in_array($request->input('genre'), $genres, false)) ? $request->input('genre') : ''; |
||
| 129 | $this->smarty->assign('genres', $genres); |
||
| 130 | $this->smarty->assign('genre', $genre); |
||
| 131 | |||
| 132 | $years = range(1903, now()->addYear()->year); |
||
| 133 | rsort($years); |
||
| 134 | $year = ($request->has('year') && \in_array($request->input('year'), $years, false)) ? $request->input('year') : ''; |
||
| 135 | $this->smarty->assign('years', $years); |
||
| 136 | $this->smarty->assign('year', $year); |
||
| 137 | |||
| 138 | if ((int) $category === -1) { |
||
| 139 | $this->smarty->assign('catname', 'All'); |
||
| 140 | } else { |
||
| 141 | $cdata = Category::find($category); |
||
| 142 | if ($cdata !== null) { |
||
| 143 | $this->smarty->assign('catname', $cdata); |
||
| 144 | } else { |
||
| 145 | $this->smarty->assign('catname', 'All'); |
||
| 146 | } |
||
| 147 | } |
||
| 148 | |||
| 149 | $this->smarty->assign( |
||
| 150 | [ |
||
| 151 | 'resultsadd'=> $movies, |
||
| 152 | 'results' => $results, |
||
| 153 | 'covgroup' => 'movies', |
||
| 154 | ] |
||
| 155 | ); |
||
| 156 | |||
| 157 | $meta_title = 'Browse Movies'; |
||
| 158 | $meta_keywords = 'browse,nzb,description,details'; |
||
| 159 | $meta_description = 'Browse for Movies'; |
||
| 160 | |||
| 161 | if ($request->has('imdb')) { |
||
| 162 | $content = $this->smarty->fetch('viewmoviefull.tpl'); |
||
| 163 | } else { |
||
| 164 | $content = $this->smarty->fetch('movies.tpl'); |
||
| 165 | } |
||
| 166 | |||
| 167 | $this->smarty->assign(compact('content', 'meta_title', 'meta_keywords', 'meta_description')); |
||
| 168 | $this->pagerender(); |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @param \Illuminate\Http\Request $request |
||
| 173 | * |
||
| 174 | * @return \Illuminate\Http\JsonResponse |
||
| 175 | * @throws \Exception |
||
| 176 | */ |
||
| 177 | public function showTrailer(Request $request) |
||
| 209 | } |
||
| 210 | } |
||
| 213 |