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