Conditions | 17 |
Paths | > 20000 |
Total Lines | 71 |
Code Lines | 51 |
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 |
||
15 | public function show(Request $request): void |
||
16 | { |
||
17 | $this->setPreferences(); |
||
18 | $games = new Games(['Settings' => $this->settings]); |
||
|
|||
19 | $gen = new Genres(['Settings' => $this->settings]); |
||
20 | |||
21 | $concats = Category::getChildren(Category::PC_ROOT); |
||
22 | $ctmp = []; |
||
23 | foreach ($concats as $ccat) { |
||
24 | $ctmp[$ccat['id']] = $ccat; |
||
25 | } |
||
26 | $category = Category::PC_GAMES; |
||
27 | if ($request->has('t') && array_key_exists($request->input('t'), $ctmp)) { |
||
28 | $category = $request->input('t') + 0; |
||
29 | } |
||
30 | |||
31 | $catarray = []; |
||
32 | $catarray[] = $category; |
||
33 | |||
34 | $this->smarty->assign('catlist', $ctmp); |
||
35 | $this->smarty->assign('category', $category); |
||
36 | |||
37 | $page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1; |
||
38 | $ordering = $games->getGamesOrdering(); |
||
39 | $orderby = $request->has('ob') && \in_array($request->input('ob'), $ordering, false) ? $request->input('ob') : ''; |
||
40 | $offset = ($page - 1) * config('nntmux.items_per_cover_page'); |
||
41 | $rslt = $games->getGamesRange($page, $catarray, $offset, config('nntmux.items_per_cover_page'), $orderby, '', $this->userdata->categoryexclusions); |
||
42 | $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_cover_page'), $page, $request->url(), $request->query()); |
||
43 | |||
44 | $title = ($request->has('title') && ! empty($request->input('title'))) ? stripslashes($request->input('title')) : ''; |
||
45 | $this->smarty->assign('title', $title); |
||
46 | |||
47 | $genres = $gen->getGenres(Genres::GAME_TYPE, true); |
||
48 | $tmpgnr = []; |
||
49 | foreach ($genres as $gn) { |
||
50 | $tmpgnr[$gn->id] = $gn->title; |
||
51 | } |
||
52 | |||
53 | $years = range(1903, date('Y') + 1); |
||
54 | rsort($years); |
||
55 | $year = ($request->has('year') && \in_array($request->input('year'), $years, false)) ? $request->input('year') : ''; |
||
56 | $this->smarty->assign('years', $years); |
||
57 | $this->smarty->assign('year', $year); |
||
58 | |||
59 | $genre = ($request->has('genre') && array_key_exists($request->input('genre'), $tmpgnr)) ? $request->input('genre') : ''; |
||
60 | $this->smarty->assign('genres', $genres); |
||
61 | $this->smarty->assign('genre', $genre); |
||
62 | |||
63 | if ((int) $category === -1) { |
||
64 | $this->smarty->assign('catname', 'All'); |
||
65 | } else { |
||
66 | $cdata = Category::find($category); |
||
67 | if ($cdata !== null) { |
||
68 | $this->smarty->assign('catname', $cdata); |
||
69 | } else { |
||
70 | $this->smarty->assign('catname', 'All'); |
||
71 | } |
||
72 | } |
||
73 | |||
74 | $this->smarty->assign('results', $results); |
||
75 | $this->smarty->assign('covgroup', 'games'); |
||
76 | |||
77 | $meta_title = 'Browse Games'; |
||
78 | $meta_keywords = 'browse,nzb,games,description,details'; |
||
79 | $meta_description = 'Browse for Games'; |
||
80 | |||
81 | $content = $this->smarty->fetch('games.tpl'); |
||
82 | $this->smarty->assign( |
||
83 | compact('content', 'meta_title', 'meta_keywords', 'meta_description') |
||
84 | ); |
||
85 | $this->pagerender(); |
||
86 | } |
||
88 |
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.