| Conditions | 8 |
| Paths | 64 |
| Total Lines | 73 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 showMovies(Request $request, string $id = '') |
||
| 15 | { |
||
| 16 | $movie = new Movie(['Settings' => $this->settings]); |
||
|
|
|||
| 17 | |||
| 18 | $moviecats = Category::getChildren(Category::MOVIE_ROOT)->map(function ($mcat) { |
||
| 19 | return ['id' => $mcat->id, 'title' => $mcat->title]; |
||
| 20 | }); |
||
| 21 | |||
| 22 | $category = $request->has('imdb') ? -1 : ($request->input('t', Category::MOVIE_ROOT)); |
||
| 23 | if ($id && $moviecats->pluck('title')->contains($id)) { |
||
| 24 | $cat = Category::where(['title' => $id, 'root_categories_id' => Category::MOVIE_ROOT])->first(['id']); |
||
| 25 | $category = $cat->id ?? Category::MOVIE_ROOT; |
||
| 26 | } |
||
| 27 | |||
| 28 | $catarray = $category !== -1 ? [$category] : []; |
||
| 29 | |||
| 30 | $page = $request->input('page', 1); |
||
| 31 | $offset = ($page - 1) * config('nntmux.items_per_cover_page'); |
||
| 32 | |||
| 33 | $orderby = $request->input('ob', ''); |
||
| 34 | $ordering = $movie->getMovieOrdering(); |
||
| 35 | if (! in_array($orderby, $ordering, false)) { |
||
| 36 | $orderby = ''; |
||
| 37 | } |
||
| 38 | |||
| 39 | $rslt = $movie->getMovieRange($page, $catarray, $offset, config('nntmux.items_per_cover_page'), $orderby, -1, $this->userdata->categoryexclusions); |
||
| 40 | $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_cover_page'), $page, $request->url(), $request->query()); |
||
| 41 | |||
| 42 | $movies = $results->map(function ($result) { |
||
| 43 | $result['genre'] = makeFieldLinks($result, 'genre', 'movies'); |
||
| 44 | $result['actors'] = makeFieldLinks($result, 'actors', 'movies'); |
||
| 45 | $result['director'] = makeFieldLinks($result, 'director', 'movies'); |
||
| 46 | $result['languages'] = explode(', ', $result['language']); |
||
| 47 | |||
| 48 | // Add cover image URL using helper function |
||
| 49 | $result['cover'] = getReleaseCover($result); |
||
| 50 | |||
| 51 | return $result; |
||
| 52 | }); |
||
| 53 | |||
| 54 | $years = range(1903, now()->addYear()->year); |
||
| 55 | rsort($years); |
||
| 56 | |||
| 57 | $catname = $category === -1 ? 'All' : Category::find($category) ?? 'All'; |
||
| 58 | |||
| 59 | $this->viewData = array_merge($this->viewData, [ |
||
| 60 | 'cpapi' => $this->userdata->cp_api, |
||
| 61 | 'cpurl' => $this->userdata->cp_url, |
||
| 62 | 'catlist' => $moviecats, |
||
| 63 | 'category' => $category, |
||
| 64 | 'categorytitle' => $id, |
||
| 65 | 'title' => stripslashes($request->input('title', '')), |
||
| 66 | 'actors' => stripslashes($request->input('actors', '')), |
||
| 67 | 'director' => stripslashes($request->input('director', '')), |
||
| 68 | 'ratings' => range(1, 9), |
||
| 69 | 'rating' => $request->input('rating', ''), |
||
| 70 | 'genres' => $movie->getGenres(), |
||
| 71 | 'genre' => $request->input('genre', ''), |
||
| 72 | 'years' => $years, |
||
| 73 | 'year' => $request->input('year', ''), |
||
| 74 | 'catname' => $catname, |
||
| 75 | 'resultsadd' => $movies, |
||
| 76 | 'results' => $results, |
||
| 77 | 'covgroup' => 'movies', |
||
| 78 | 'meta_title' => 'Browse Movies', |
||
| 79 | 'meta_keywords' => 'browse,nzb,description,details', |
||
| 80 | 'meta_description' => 'Browse for Movies', |
||
| 81 | ]); |
||
| 82 | |||
| 83 | // Return the appropriate view |
||
| 84 | $viewName = $request->has('imdb') ? 'movies.viewmoviefull' : 'movies.index'; |
||
| 85 | |||
| 86 | return view($viewName, $this->viewData); |
||
| 87 | } |
||
| 219 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.