Conditions | 8 |
Paths | 64 |
Total Lines | 73 |
Code Lines | 51 |
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 = ''): void |
||
15 | { |
||
16 | $this->setPreferences(); |
||
17 | $movie = new Movie(['Settings' => $this->settings]); |
||
|
|||
18 | |||
19 | $moviecats = Category::getChildren(Category::MOVIE_ROOT)->map(function ($mcat) { |
||
20 | return ['id' => $mcat->id, 'title' => $mcat->title]; |
||
21 | }); |
||
22 | |||
23 | $category = $request->has('imdb') ? -1 : ($request->input('t', Category::MOVIE_ROOT)); |
||
24 | if ($id && $moviecats->pluck('title')->contains($id)) { |
||
25 | $cat = Category::where(['title' => $id, 'root_categories_id' => Category::MOVIE_ROOT])->first(['id']); |
||
26 | $category = $cat->id ?? Category::MOVIE_ROOT; |
||
27 | } |
||
28 | |||
29 | $this->smarty->assign('cpapi', $this->userdata->cp_api); |
||
30 | $this->smarty->assign('cpurl', $this->userdata->cp_url); |
||
31 | |||
32 | $catarray = $category !== -1 ? [$category] : []; |
||
33 | |||
34 | $this->smarty->assign('catlist', $moviecats); |
||
35 | $this->smarty->assign('category', $category); |
||
36 | $this->smarty->assign('categorytitle', $id); |
||
37 | |||
38 | $page = $request->input('page', 1); |
||
39 | $offset = ($page - 1) * config('nntmux.items_per_cover_page'); |
||
40 | |||
41 | $orderby = $request->input('ob', ''); |
||
42 | $ordering = $movie->getMovieOrdering(); |
||
43 | if (! in_array($orderby, $ordering, false)) { |
||
44 | $orderby = ''; |
||
45 | } |
||
46 | |||
47 | $rslt = $movie->getMovieRange($page, $catarray, $offset, config('nntmux.items_per_cover_page'), $orderby, -1, $this->userdata->categoryexclusions); |
||
48 | $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_cover_page'), $page, $request->url(), $request->query()); |
||
49 | |||
50 | $movies = $results->map(function ($result) { |
||
51 | $result['genre'] = makeFieldLinks($result, 'genre', 'movies'); |
||
52 | $result['actors'] = makeFieldLinks($result, 'actors', 'movies'); |
||
53 | $result['director'] = makeFieldLinks($result, 'director', 'movies'); |
||
54 | $result['languages'] = explode(', ', $result['language']); |
||
55 | |||
56 | return $result; |
||
57 | }); |
||
58 | |||
59 | $this->smarty->assign('title', stripslashes($request->input('title', ''))); |
||
60 | $this->smarty->assign('actors', stripslashes($request->input('actors', ''))); |
||
61 | $this->smarty->assign('director', stripslashes($request->input('director', ''))); |
||
62 | $this->smarty->assign('ratings', range(1, 9)); |
||
63 | $this->smarty->assign('rating', $request->input('rating', '')); |
||
64 | $this->smarty->assign('genres', $movie->getGenres()); |
||
65 | $this->smarty->assign('genre', $request->input('genre', '')); |
||
66 | $years = range(1903, now()->addYear()->year); |
||
67 | rsort($years); |
||
68 | $this->smarty->assign('years', $years); |
||
69 | $this->smarty->assign('year', $request->input('year', '')); |
||
70 | |||
71 | $catname = $category === -1 ? 'All' : Category::find($category) ?? 'All'; |
||
72 | $this->smarty->assign('catname', $catname); |
||
73 | |||
74 | $this->smarty->assign([ |
||
75 | 'resultsadd' => $movies, |
||
76 | 'results' => $results, |
||
77 | 'covgroup' => 'movies', |
||
78 | ]); |
||
79 | |||
80 | $meta_title = 'Browse Movies'; |
||
81 | $meta_keywords = 'browse,nzb,description,details'; |
||
82 | $meta_description = 'Browse for Movies'; |
||
83 | |||
84 | $content = $request->has('imdb') ? $this->smarty->fetch('viewmoviefull.tpl') : $this->smarty->fetch('movies.tpl'); |
||
85 | $this->smarty->assign(compact('content', 'meta_title', 'meta_keywords', 'meta_description')); |
||
86 | $this->pagerender(); |
||
87 | } |
||
128 |
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.