| Conditions | 23 |
| Paths | 3840 |
| Total Lines | 86 |
| Code Lines | 62 |
| 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 |
||
| 49 | public function show(Request $request, string $parentCategory, string $id = 'All') |
||
| 50 | { |
||
| 51 | $releases = new Releases; |
||
| 52 | |||
| 53 | $parentId = RootCategory::query()->where('title', $parentCategory)->value('id'); |
||
| 54 | |||
| 55 | $query = Category::query()->where('title', $id)->where('root_categories_id', $parentId); |
||
| 56 | if ($id !== 'All') { |
||
| 57 | $cat = $query->first(); |
||
| 58 | $category = $cat !== null ? $cat->id : -1; |
||
| 59 | } else { |
||
| 60 | $category = $parentId ?? -1; |
||
| 61 | } |
||
| 62 | |||
| 63 | $grp = -1; |
||
| 64 | |||
| 65 | $catarray = []; |
||
| 66 | $catarray[] = $category; |
||
| 67 | |||
| 68 | $ordering = $releases->getBrowseOrdering(); |
||
| 69 | $orderBy = $request->has('ob') && ! empty($request->input('ob')) ? $request->input('ob') : ''; |
||
| 70 | $page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1; |
||
| 71 | $offset = ($page - 1) * config('nntmux.items_per_page'); |
||
| 72 | |||
| 73 | $rslt = $releases->getBrowseRange($page, $catarray, $offset, config('nntmux.items_per_page'), $orderBy, -1, $this->userdata->categoryexclusions, $grp); |
||
| 74 | $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_page'), $page, $request->url(), $request->query()); |
||
| 75 | |||
| 76 | $covgroup = ''; |
||
| 77 | $shows = false; |
||
| 78 | if ($category === -1 && $grp === -1) { |
||
| 79 | $catname = 'All'; |
||
| 80 | } elseif ($category !== -1 && $grp === -1) { |
||
| 81 | $catname = $id; |
||
| 82 | $cdata = Category::find($category); |
||
| 83 | if ($cdata !== null) { |
||
| 84 | if ($cdata->root_categories_id === Category::GAME_ROOT) { |
||
| 85 | $covgroup = 'console'; |
||
| 86 | } elseif ($cdata->root_categories_id === Category::MOVIE_ROOT) { |
||
| 87 | $covgroup = 'movies'; |
||
| 88 | } elseif ($cdata->root_categories_id === Category::PC_ROOT) { |
||
| 89 | $covgroup = 'games'; |
||
| 90 | } elseif ($cdata->root_categories_id === Category::MUSIC_ROOT) { |
||
| 91 | $covgroup = 'music'; |
||
| 92 | } elseif ($cdata->root_categories_id === Category::BOOKS_ROOT) { |
||
| 93 | $covgroup = 'books'; |
||
| 94 | } elseif ($cdata->root_categories_id === Category::TV_ROOT) { |
||
| 95 | $shows = true; |
||
| 96 | } |
||
| 97 | } |
||
| 98 | } else { |
||
| 99 | $catname = $grp; |
||
| 100 | } |
||
| 101 | |||
| 102 | // Build order by URLs |
||
| 103 | $orderByUrls = []; |
||
| 104 | if ($id === 'All' && $parentCategory === 'All') { |
||
| 105 | $meta_title = 'Browse '.$parentCategory.' releases'; |
||
| 106 | foreach ($ordering as $orderType) { |
||
| 107 | $orderByUrls['orderby'.$orderType] = url('browse/'.$parentCategory.'?ob='.$orderType); |
||
| 108 | } |
||
| 109 | } else { |
||
| 110 | $meta_title = 'Browse '.$parentCategory.' / '.$id.' releases'; |
||
| 111 | foreach ($ordering as $orderType) { |
||
| 112 | $orderByUrls['orderby'.$orderType] = url('browse/'.$parentCategory.'/'.$id.'?ob='.$orderType); |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | $viewData = [ |
||
| 117 | 'parentcat' => ucfirst($parentCategory), |
||
| 118 | 'category' => $category, |
||
| 119 | 'catname' => $catname, |
||
| 120 | 'results' => $results, |
||
| 121 | 'lastvisit' => $this->userdata->lastlogin, |
||
| 122 | 'covgroup' => $covgroup, |
||
| 123 | 'meta_title' => $meta_title, |
||
| 124 | 'meta_keywords' => 'browse,nzb,description,details', |
||
| 125 | 'meta_description' => 'Browse for Nzbs', |
||
| 126 | ]; |
||
| 127 | |||
| 128 | if ($shows) { |
||
| 129 | $viewData['shows'] = true; |
||
| 130 | } |
||
| 131 | |||
| 132 | $this->viewData = array_merge($this->viewData, $viewData, $orderByUrls); |
||
| 133 | |||
| 134 | return view('browse.index', $this->viewData); |
||
| 135 | } |
||
| 166 |