| Total Complexity | 72 |
| Total Lines | 246 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like RssController 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 RssController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 15 | class RssController extends BasePageController |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @return JsonResponse|void |
||
| 19 | * |
||
| 20 | * @throws \Throwable |
||
| 21 | */ |
||
| 22 | public function myMoviesRss(Request $request) |
||
| 23 | { |
||
| 24 | $rss = new RSS(['Settings' => $this->settings]); |
||
|
|
|||
| 25 | $offset = 0; |
||
| 26 | |||
| 27 | $user = $this->userCheck($request); |
||
| 28 | |||
| 29 | if (is_object($user)) { |
||
| 30 | return $user; |
||
| 31 | } |
||
| 32 | |||
| 33 | $outputXML = (! ($request->has('o') && $request->input('o') === 'json')); |
||
| 34 | |||
| 35 | $userNum = ($request->has('num') && is_numeric($request->input('num')) ? abs($request->input('num')) : 0); |
||
| 36 | |||
| 37 | $relData = $rss->getMyMoviesRss($userNum, $user['user_id'], User::getCategoryExclusionById($user['user_id'])); |
||
| 38 | |||
| 39 | $rss->output($relData, $user['params'], $outputXML, $offset, 'rss'); |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @return JsonResponse|void |
||
| 44 | * |
||
| 45 | * @throws \Throwable |
||
| 46 | */ |
||
| 47 | public function myShowsRss(Request $request) |
||
| 48 | { |
||
| 49 | $rss = new RSS; |
||
| 50 | $offset = 0; |
||
| 51 | $user = $this->userCheck($request); |
||
| 52 | if (is_object($user)) { |
||
| 53 | return $user; |
||
| 54 | } |
||
| 55 | $userAirDate = $request->has('airdate') && is_numeric($request->input('airdate')) ? abs($request->input('airdate')) : -1; |
||
| 56 | $userNum = ($request->has('num') && is_numeric($request->input('num')) ? abs($request->input('num')) : 0); |
||
| 57 | $relData = $rss->getShowsRss($userNum, $user['user_id'], User::getCategoryExclusionById($user['user_id']), $userAirDate); |
||
| 58 | $outputXML = (! ($request->has('o') && $request->input('o') === 'json')); |
||
| 59 | |||
| 60 | $rss->output($relData, $user['params'], $outputXML, $offset, 'rss'); |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @return JsonResponse|void |
||
| 65 | * |
||
| 66 | * @throws \Throwable |
||
| 67 | */ |
||
| 68 | public function fullFeedRss(Request $request) |
||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @throws \Exception |
||
| 92 | */ |
||
| 93 | public function showRssDesc() |
||
| 94 | { |
||
| 95 | $rss = new RSS; |
||
| 96 | |||
| 97 | $firstShow = $rss->getFirstInstance('videos_id', 'releases', 'id'); |
||
| 98 | $firstAni = $rss->getFirstInstance('anidbid', 'releases', 'id'); |
||
| 99 | |||
| 100 | $show = ($firstShow !== null) ? $firstShow->videos_id : 1; |
||
| 101 | $anidb = ($firstAni !== null) ? $firstAni->anidbid : 1; |
||
| 102 | |||
| 103 | $catExclusions = $this->userdata->categoryexclusions ?? []; |
||
| 104 | |||
| 105 | $this->viewData = array_merge($this->viewData, [ |
||
| 106 | 'show' => $show, |
||
| 107 | 'anidb' => $anidb, |
||
| 108 | 'categorylist' => Category::getCategories(true, $catExclusions), |
||
| 109 | 'parentcategorylist' => Category::getForMenu($catExclusions), |
||
| 110 | 'title' => 'Rss Info', |
||
| 111 | 'meta_title' => 'Rss Nzb Info', |
||
| 112 | 'meta_keywords' => 'view,nzb,description,details,rss,atom', |
||
| 113 | 'meta_description' => 'View information about NNTmux RSS Feeds.', |
||
| 114 | ]); |
||
| 115 | |||
| 116 | return view('rss.rssdesc', $this->viewData); |
||
| 117 | } |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @throws \Throwable |
||
| 121 | */ |
||
| 122 | public function cartRss(Request $request) |
||
| 123 | { |
||
| 124 | $rss = new RSS; |
||
| 125 | $offset = 0; |
||
| 126 | $user = $this->userCheck($request); |
||
| 127 | if (is_object($user)) { |
||
| 128 | return $user; |
||
| 129 | } |
||
| 130 | $outputXML = (! ($request->has('o') && $request->input('o') === 'json')); |
||
| 131 | $userAirDate = $request->has('airdate') && is_numeric($request->input('airdate')) ? abs($request->input('airdate')) : -1; |
||
| 132 | $userNum = ($request->has('num') && is_numeric($request->input('num')) ? abs($request->input('num')) : 0); |
||
| 133 | $userLimit = $request->has('limit') && is_numeric($request->input('limit')) ? $request->input('limit') : 100; |
||
| 134 | $userShow = $userAnidb = -1; |
||
| 135 | if ($request->has('show')) { |
||
| 136 | $userShow = ((int) $request->input('show') === 0 ? -1 : $request->input('show') + 0); |
||
| 137 | } elseif ($request->has('anidb')) { |
||
| 138 | $userAnidb = ((int) $request->input('anidb') === 0 ? -1 : $request->input('anidb') + 0); |
||
| 139 | } |
||
| 140 | |||
| 141 | $relData = $rss->getRss([-2], $userShow, $userAnidb, $user['user_id'], $userAirDate, $userLimit, $userNum); |
||
| 142 | $rss->output($relData, $user['params'], $outputXML, $offset, 'rss'); |
||
| 143 | } |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @throws \Throwable |
||
| 147 | */ |
||
| 148 | public function categoryFeedRss(Request $request) |
||
| 173 | } |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @throws \Throwable |
||
| 177 | */ |
||
| 178 | public function trendingMoviesRss(Request $request) |
||
| 179 | { |
||
| 180 | $rss = new RSS; |
||
| 181 | $offset = 0; |
||
| 182 | $user = $this->userCheck($request); |
||
| 183 | if (is_object($user)) { |
||
| 184 | return $user; |
||
| 185 | } |
||
| 186 | $outputXML = (! ($request->has('o') && $request->input('o') === 'json')); |
||
| 187 | |||
| 188 | $relData = $rss->getTrendingMoviesRss(); |
||
| 189 | |||
| 190 | $rss->output($relData, $user['params'], $outputXML, $offset, 'rss'); |
||
| 191 | } |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @throws \Throwable |
||
| 195 | */ |
||
| 196 | public function trendingShowsRss(Request $request) |
||
| 209 | } |
||
| 210 | |||
| 211 | /** |
||
| 212 | * @throws \Throwable |
||
| 213 | */ |
||
| 214 | private function userCheck(Request $request): JsonResponse|array |
||
| 263 |
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.