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