| Total Complexity | 41 |
| Total Lines | 221 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
Complex classes like BrowseController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use BrowseController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 10 | class BrowseController extends BasePageController |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @throws \Exception |
||
| 14 | */ |
||
| 15 | public function index() |
||
| 16 | { |
||
| 17 | $this->setPrefs(); |
||
| 18 | $releases = new Releases(); |
||
| 19 | |||
| 20 | $this->smarty->assign('category', -1); |
||
|
|
|||
| 21 | |||
| 22 | $ordering = $releases->getBrowseOrdering(); |
||
| 23 | $orderBy = request()->has('ob') && ! empty(request()->input('ob')) ? request()->input('ob') : ''; |
||
| 24 | $page = request()->has('page') && is_numeric(request()->input('page')) ? request()->input('page') : 1; |
||
| 25 | $offset = ($page - 1) * config('nntmux.items_per_page'); |
||
| 26 | |||
| 27 | $rslt = $releases->getBrowseRange($page, [-1], $offset, config('nntmux.items_per_page'), $orderBy, -1, $this->userdata->categoryexclusions, -1); |
||
| 28 | $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_page'), $page, request()->url(), request()->query()); |
||
| 29 | |||
| 30 | $this->smarty->assign('catname', 'All'); |
||
| 31 | |||
| 32 | $this->smarty->assign('lastvisit', $this->userdata->lastlogin); |
||
| 33 | |||
| 34 | $browse = []; |
||
| 35 | foreach ($results as $result) { |
||
| 36 | $browse[] = $result; |
||
| 37 | } |
||
| 38 | |||
| 39 | $this->smarty->assign( |
||
| 40 | [ |
||
| 41 | 'results' => $results, |
||
| 42 | 'resultsadd' => $browse, |
||
| 43 | ] |
||
| 44 | ); |
||
| 45 | |||
| 46 | foreach ($ordering as $orderType) { |
||
| 47 | $this->smarty->assign('orderby'.$orderType, url('browse/All?ob='.$orderType)); |
||
| 48 | } |
||
| 49 | |||
| 50 | $meta_title = 'Browse All Releases'; |
||
| 51 | $meta_keywords = 'browse,nzb,description,details'; |
||
| 52 | $meta_description = 'Browse for Nzbs'; |
||
| 53 | |||
| 54 | $content = $this->smarty->fetch('browse.tpl'); |
||
| 55 | $this->smarty->assign(compact('content', 'meta_title', 'meta_keywords', 'meta_description')); |
||
| 56 | $this->pagerender(); |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @param string $parentCategory |
||
| 61 | * @param string $id |
||
| 62 | * @throws \Exception |
||
| 63 | */ |
||
| 64 | public function show(string $parentCategory, string $id = 'All') |
||
| 65 | { |
||
| 66 | $this->setPrefs(); |
||
| 67 | $releases = new Releases(); |
||
| 68 | |||
| 69 | $parentId = RootCategory::query()->where('title', $parentCategory)->value('id'); |
||
| 70 | |||
| 71 | $query = Category::query()->where('title', $id)->where('root_categories_id', $parentId); |
||
| 72 | if ($id !== 'All') { |
||
| 73 | $cat = $query->first(); |
||
| 74 | $category = $cat !== null ? $cat->id : -1; |
||
| 75 | } else { |
||
| 76 | $category = $parentId ?? -1; |
||
| 77 | } |
||
| 78 | |||
| 79 | $grp = -1; |
||
| 80 | |||
| 81 | $catarray = []; |
||
| 82 | $catarray[] = $category; |
||
| 83 | |||
| 84 | $this->smarty->assign('parentcat', ucfirst($parentCategory)); |
||
| 85 | $this->smarty->assign('category', $category); |
||
| 86 | |||
| 87 | $ordering = $releases->getBrowseOrdering(); |
||
| 88 | $orderBy = request()->has('ob') && ! empty(request()->input('ob')) ? request()->input('ob') : ''; |
||
| 89 | $page = request()->has('page') && is_numeric(request()->input('page')) ? request()->input('page') : 1; |
||
| 90 | $offset = ($page - 1) * config('nntmux.items_per_page'); |
||
| 91 | |||
| 92 | $rslt = $releases->getBrowseRange($page, $catarray, $offset, config('nntmux.items_per_page'), $orderBy, -1, $this->userdata->categoryexclusions, $grp); |
||
| 93 | $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_page'), $page, request()->url(), request()->query()); |
||
| 94 | |||
| 95 | $browse = []; |
||
| 96 | |||
| 97 | foreach ($results as $result) { |
||
| 98 | $browse[] = $result; |
||
| 99 | } |
||
| 100 | |||
| 101 | $this->smarty->assign('catname', $id); |
||
| 102 | |||
| 103 | $this->smarty->assign('lastvisit', $this->userdata->lastlogin); |
||
| 104 | |||
| 105 | $this->smarty->assign( |
||
| 106 | [ |
||
| 107 | 'results' => $results, |
||
| 108 | 'resultsadd' => $browse, |
||
| 109 | ] |
||
| 110 | ); |
||
| 111 | |||
| 112 | $covgroup = ''; |
||
| 113 | if ($category === -1 && $grp === -1) { |
||
| 114 | $this->smarty->assign('catname', 'All'); |
||
| 115 | } elseif ($category !== -1 && $grp === -1) { |
||
| 116 | $cdata = Category::find($category); |
||
| 117 | if ($cdata !== null) { |
||
| 118 | if ($cdata->root_categories_id === Category::GAME_ROOT) { |
||
| 119 | $covgroup = 'console'; |
||
| 120 | } elseif ($cdata->root_categories_id === Category::MOVIE_ROOT) { |
||
| 121 | $covgroup = 'movies'; |
||
| 122 | } elseif ($cdata->root_categories_id === Category::XXX_ROOT) { |
||
| 123 | $covgroup = 'xxx'; |
||
| 124 | } elseif ($cdata->root_categories_id === Category::PC_ROOT) { |
||
| 125 | $covgroup = 'games'; |
||
| 126 | } elseif ($cdata->root_categories_id === Category::MUSIC_ROOT) { |
||
| 127 | $covgroup = 'music'; |
||
| 128 | } elseif ($cdata->root_categories_id === Category::BOOKS_ROOT) { |
||
| 129 | $covgroup = 'books'; |
||
| 130 | } |
||
| 131 | } |
||
| 132 | } elseif ($grp !== -1) { |
||
| 133 | $this->smarty->assign('catname', $grp); |
||
| 134 | } |
||
| 135 | |||
| 136 | if ($id === 'All' && $parentCategory === 'All') { |
||
| 137 | $meta_title = 'Browse '.$parentCategory.' releases'; |
||
| 138 | foreach ($ordering as $orderType) { |
||
| 139 | $this->smarty->assign('orderby'.$orderType, url('browse/'.$parentCategory.'?ob='.$orderType)); |
||
| 140 | } |
||
| 141 | } else { |
||
| 142 | $meta_title = 'Browse '.$parentCategory.' / '.$id.' releases'; |
||
| 143 | foreach ($ordering as $orderType) { |
||
| 144 | $this->smarty->assign('orderby'.$orderType, url('browse/'.$parentCategory.'/'.$id.'?ob='.$orderType)); |
||
| 145 | } |
||
| 146 | } |
||
| 147 | $meta_keywords = 'browse,nzb,description,details'; |
||
| 148 | $meta_description = 'Browse for Nzbs'; |
||
| 149 | |||
| 150 | $content = $this->smarty->fetch('browse.tpl'); |
||
| 151 | $this->smarty->assign(compact('content', 'covgroup', 'meta_title', 'meta_keywords', 'meta_description')); |
||
| 152 | $this->pagerender(); |
||
| 153 | } |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @param \Illuminate\Http\Request $request |
||
| 157 | * @throws \Exception |
||
| 158 | */ |
||
| 159 | public function group(Request $request) |
||
| 160 | { |
||
| 161 | $this->setPrefs(); |
||
| 162 | $releases = new Releases(); |
||
| 163 | if ($request->has('g')) { |
||
| 164 | $group = $request->input('g'); |
||
| 165 | $page = request()->has('page') && is_numeric(request()->input('page')) ? request()->input('page') : 1; |
||
| 166 | $offset = ($page - 1) * config('nntmux.items_per_page'); |
||
| 167 | $rslt = $releases->getBrowseRange($page, [-1], $offset, config('nntmux.items_per_page'), '', -1, $this->userdata->categoryexclusions, $group); |
||
| 168 | $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_page'), $page, request()->url(), request()->query()); |
||
| 169 | |||
| 170 | $browse = []; |
||
| 171 | |||
| 172 | foreach ($results as $result) { |
||
| 173 | $browse[] = $result; |
||
| 174 | } |
||
| 175 | |||
| 176 | $this->smarty->assign( |
||
| 177 | [ |
||
| 178 | 'results' => $results, |
||
| 179 | 'resultsadd' => $browse, |
||
| 180 | 'parentcat' => $group, |
||
| 181 | 'catname' => 'all', |
||
| 182 | ] |
||
| 183 | ); |
||
| 184 | $meta_title = 'Browse Groups'; |
||
| 185 | $meta_keywords = 'browse,nzb,description,details'; |
||
| 186 | $meta_description = 'Browse Groups'; |
||
| 187 | $content = $this->smarty->fetch('browse.tpl'); |
||
| 188 | |||
| 189 | $this->smarty->assign(compact('content', 'meta_title', 'meta_keywords', 'meta_description')); |
||
| 190 | |||
| 191 | $this->pagerender(); |
||
| 192 | } |
||
| 193 | } |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @param \Illuminate\Http\Request $request |
||
| 197 | * @throws \Exception |
||
| 198 | */ |
||
| 199 | public function tags(Request $request) |
||
| 231 | } |
||
| 232 | } |
||
| 233 | } |
||
| 234 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.