| Conditions | 28 |
| Paths | > 20000 |
| Total Lines | 110 |
| Code Lines | 75 |
| 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 |
||
| 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 | } |
||
| 213 |