Conditions | 24 |
Paths | 4224 |
Total Lines | 89 |
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 |
||
62 | public function show(Request $request, string $parentCategory, string $id = 'All'): void |
||
63 | { |
||
64 | $this->setPreferences(); |
||
65 | $releases = new Releases; |
||
66 | |||
67 | $parentId = RootCategory::query()->where('title', $parentCategory)->value('id'); |
||
68 | |||
69 | $query = Category::query()->where('title', $id)->where('root_categories_id', $parentId); |
||
70 | if ($id !== 'All') { |
||
71 | $cat = $query->first(); |
||
72 | $category = $cat !== null ? $cat->id : -1; |
||
73 | } else { |
||
74 | $category = $parentId ?? -1; |
||
75 | } |
||
76 | |||
77 | $grp = -1; |
||
78 | |||
79 | $catarray = []; |
||
80 | $catarray[] = $category; |
||
81 | |||
82 | $this->smarty->assign('parentcat', ucfirst($parentCategory)); |
||
83 | $this->smarty->assign('category', $category); |
||
84 | |||
85 | $ordering = $releases->getBrowseOrdering(); |
||
86 | $orderBy = $request->has('ob') && ! empty($request->input('ob')) ? $request->input('ob') : ''; |
||
87 | $page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1; |
||
88 | $offset = ($page - 1) * config('nntmux.items_per_page'); |
||
89 | |||
90 | $rslt = $releases->getBrowseRange($page, $catarray, $offset, config('nntmux.items_per_page'), $orderBy, -1, $this->userdata->categoryexclusions, $grp); |
||
91 | $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_page'), $page, $request->url(), $request->query()); |
||
92 | |||
93 | $browse = []; |
||
94 | |||
95 | foreach ($results as $result) { |
||
96 | $browse[] = $result; |
||
97 | } |
||
98 | |||
99 | $this->smarty->assign('catname', $id); |
||
100 | |||
101 | $this->smarty->assign('lastvisit', $this->userdata->lastlogin); |
||
102 | |||
103 | $this->smarty->assign( |
||
104 | [ |
||
105 | 'results' => $results, |
||
106 | 'resultsadd' => $browse, |
||
107 | ] |
||
108 | ); |
||
109 | |||
110 | $covgroup = ''; |
||
111 | if ($category === -1 && $grp === -1) { |
||
112 | $this->smarty->assign('catname', 'All'); |
||
113 | } elseif ($category !== -1 && $grp === -1) { |
||
114 | $cdata = Category::find($category); |
||
115 | if ($cdata !== null) { |
||
116 | if ($cdata->root_categories_id === Category::GAME_ROOT) { |
||
117 | $covgroup = 'console'; |
||
118 | } elseif ($cdata->root_categories_id === Category::MOVIE_ROOT) { |
||
119 | $covgroup = 'movies'; |
||
120 | } elseif ($cdata->root_categories_id === Category::XXX_ROOT) { |
||
121 | $covgroup = 'xxx'; |
||
122 | } elseif ($cdata->root_categories_id === Category::PC_ROOT) { |
||
123 | $covgroup = 'games'; |
||
124 | } elseif ($cdata->root_categories_id === Category::MUSIC_ROOT) { |
||
125 | $covgroup = 'music'; |
||
126 | } elseif ($cdata->root_categories_id === Category::BOOKS_ROOT) { |
||
127 | $covgroup = 'books'; |
||
128 | } |
||
129 | } |
||
130 | } elseif ($grp !== -1) { |
||
131 | $this->smarty->assign('catname', $grp); |
||
132 | } |
||
133 | |||
134 | if ($id === 'All' && $parentCategory === 'All') { |
||
135 | $meta_title = 'Browse '.$parentCategory.' releases'; |
||
136 | foreach ($ordering as $orderType) { |
||
137 | $this->smarty->assign('orderby'.$orderType, url('browse/'.$parentCategory.'?ob='.$orderType)); |
||
138 | } |
||
139 | } else { |
||
140 | $meta_title = 'Browse '.$parentCategory.' / '.$id.' releases'; |
||
141 | foreach ($ordering as $orderType) { |
||
142 | $this->smarty->assign('orderby'.$orderType, url('browse/'.$parentCategory.'/'.$id.'?ob='.$orderType)); |
||
143 | } |
||
144 | } |
||
145 | $meta_keywords = 'browse,nzb,description,details'; |
||
146 | $meta_description = 'Browse for Nzbs'; |
||
147 | |||
148 | $content = $this->smarty->fetch('browse.tpl'); |
||
149 | $this->smarty->assign(compact('content', 'covgroup', 'meta_title', 'meta_keywords', 'meta_description')); |
||
150 | $this->pagerender(); |
||
151 | } |
||
192 |