| Conditions | 24 |
| Paths | > 20000 |
| Total Lines | 95 |
| Code Lines | 68 |
| 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 |
||
| 16 | public function show(Request $request, string $id = '') |
||
| 17 | { |
||
| 18 | $music = new Music(['Settings' => $this->settings]); |
||
|
|
|||
| 19 | $gen = new Genres(['Settings' => $this->settings]); |
||
| 20 | |||
| 21 | $musiccats = Category::getChildren(Category::MUSIC_ROOT); |
||
| 22 | $mtmp = []; |
||
| 23 | foreach ($musiccats as $mcat) { |
||
| 24 | $mtmp[] = |
||
| 25 | [ |
||
| 26 | 'id' => $mcat->id, |
||
| 27 | 'title' => $mcat->title, |
||
| 28 | ]; |
||
| 29 | } |
||
| 30 | |||
| 31 | $category = $request->has('t') ? $request->input('t') : Category::MUSIC_ROOT; |
||
| 32 | if ($id && \in_array($id, Arr::pluck($mtmp, 'title'), false)) { |
||
| 33 | $cat = Category::query() |
||
| 34 | ->where('title', $id) |
||
| 35 | ->where('root_categories_id', '=', Category::MUSIC_ROOT) |
||
| 36 | ->first(['id']); |
||
| 37 | $category = $cat !== null ? $cat['id'] : Category::MUSIC_ROOT; |
||
| 38 | } |
||
| 39 | |||
| 40 | $catarray = []; |
||
| 41 | $catarray[] = $category; |
||
| 42 | |||
| 43 | $page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1; |
||
| 44 | $offset = ($page - 1) * config('nntmux.items_per_cover_page'); |
||
| 45 | $ordering = $music->getMusicOrdering(); |
||
| 46 | $orderby = $request->has('ob') && \in_array($request->input('ob'), $ordering, false) ? $request->input('ob') : ''; |
||
| 47 | |||
| 48 | $musics = []; |
||
| 49 | $rslt = $music->getMusicRange($page, $catarray, $offset, config('nntmux.items_per_cover_page'), $orderby, $this->userdata->categoryexclusions); |
||
| 50 | $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_cover_page'), $page, $request->url(), $request->query()); |
||
| 51 | |||
| 52 | $artist = ($request->has('artist') && ! empty($request->input('artist'))) ? stripslashes($request->input('artist')) : ''; |
||
| 53 | |||
| 54 | $title = ($request->has('title') && ! empty($request->input('title'))) ? stripslashes($request->input('title')) : ''; |
||
| 55 | |||
| 56 | $genres = $gen->getGenres(Genres::MUSIC_TYPE, true); |
||
| 57 | $tmpgnr = []; |
||
| 58 | foreach ($genres as $gn) { |
||
| 59 | $tmpgnr[$gn->id] = $gn->title; |
||
| 60 | } |
||
| 61 | |||
| 62 | foreach ($results as $result) { |
||
| 63 | $res = $result; |
||
| 64 | $result->genre = $tmpgnr[$res->genres_id]; |
||
| 65 | $musics[] = $result; |
||
| 66 | } |
||
| 67 | |||
| 68 | $genre = ($request->has('genre') && array_key_exists($request->input('genre'), $tmpgnr)) ? $request->input('genre') : ''; |
||
| 69 | |||
| 70 | $years = range(1950, date('Y') + 1); |
||
| 71 | rsort($years); |
||
| 72 | $year = ($request->has('year') && \in_array($request->input('year'), $years, false)) ? $request->input('year') : ''; |
||
| 73 | |||
| 74 | if ((int) $category === -1) { |
||
| 75 | $catname = 'All'; |
||
| 76 | } else { |
||
| 77 | $cdata = Category::find($category); |
||
| 78 | if ($cdata !== null) { |
||
| 79 | $catname = $cdata->title; |
||
| 80 | } else { |
||
| 81 | $catname = 'All'; |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | // Build order by URLs |
||
| 86 | $orderByUrls = []; |
||
| 87 | foreach ($ordering as $orderType) { |
||
| 88 | $orderByUrls['orderby'.$orderType] = url('music/'.($id ?: 'All').'?ob='.$orderType); |
||
| 89 | } |
||
| 90 | |||
| 91 | $this->viewData = array_merge($this->viewData, [ |
||
| 92 | 'catlist' => $mtmp, |
||
| 93 | 'category' => $category, |
||
| 94 | 'categorytitle' => $id, |
||
| 95 | 'catname' => $catname, |
||
| 96 | 'artist' => $artist, |
||
| 97 | 'title' => $title, |
||
| 98 | 'genres' => $genres, |
||
| 99 | 'genre' => $genre, |
||
| 100 | 'years' => $years, |
||
| 101 | 'year' => $year, |
||
| 102 | 'resultsadd' => $musics, |
||
| 103 | 'results' => $results, |
||
| 104 | 'covgroup' => 'music', |
||
| 105 | 'meta_title' => 'Browse Albums', |
||
| 106 | 'meta_keywords' => 'browse,nzb,albums,description,details', |
||
| 107 | 'meta_description' => 'Browse for Albums', |
||
| 108 | ], $orderByUrls); |
||
| 109 | |||
| 110 | return view('music.index', $this->viewData); |
||
| 111 | } |
||
| 113 |
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.