| Conditions | 22 |
| Paths | > 20000 |
| Total Lines | 78 |
| Code Lines | 56 |
| 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 |
||
| 15 | public function show(Request $request, string $id = '') |
||
| 16 | { |
||
| 17 | $adult = new XXX; |
||
| 18 | |||
| 19 | $moviecats = Category::getChildren(Category::XXX_ROOT); |
||
| 20 | $mtmp = []; |
||
| 21 | foreach ($moviecats as $mcat) { |
||
| 22 | $mtmp[] = |
||
| 23 | [ |
||
| 24 | 'id' => $mcat->id, |
||
| 25 | 'title' => $mcat->title, |
||
| 26 | ]; |
||
| 27 | } |
||
| 28 | $category = $request->has('t') ? $request->input('t') : Category::XXX_ROOT; |
||
| 29 | if ($id && \in_array($id, Arr::pluck($mtmp, 'title'), false)) { |
||
| 30 | $cat = Category::query() |
||
| 31 | ->where('title', $id) |
||
| 32 | ->where('root_categories_id', '=', Category::XXX_ROOT) |
||
| 33 | ->first(['id']); |
||
| 34 | $category = $cat !== null ? $cat['id'] : Category::XXX_ROOT; |
||
| 35 | } |
||
| 36 | $catarray = []; |
||
| 37 | $catarray[] = $category; |
||
| 38 | |||
| 39 | $ordering = $adult->getXXXOrdering(); |
||
| 40 | $orderby = $request->has('ob') && \in_array($request->input('ob'), $ordering, false) ? $request->input('ob') : ''; |
||
| 41 | |||
| 42 | $page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1; |
||
| 43 | $offset = ($page - 1) * config('nntmux.items_per_page'); |
||
| 44 | $rslt = $adult->getXXXRange($page, $catarray, $offset, config('nntmux.items_per_page'), $orderby, -1, $this->userdata['categoryexclusions']); |
||
| 45 | $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_page'), $page, $request->url(), $request->query()); |
||
| 46 | |||
| 47 | $title = ($request->has('title') && ! empty($request->input('title'))) ? stripslashes($request->input('title')) : ''; |
||
| 48 | |||
| 49 | $actors = ($request->has('actors') && ! empty($request->input('actors'))) ? stripslashes($request->input('actors')) : ''; |
||
| 50 | |||
| 51 | $director = ($request->has('director') && ! empty($request->input('director'))) ? stripslashes($request->input('director')) : ''; |
||
| 52 | |||
| 53 | $genres = $adult->getAllGenres(true); |
||
| 54 | $genre = ($request->has('genre') && \in_array($request->input('genre'), $genres, false)) ? $request->input('genre') : ''; |
||
| 55 | |||
| 56 | $browseby_link = '&title='.$title.'&actors='.$actors.'&director='.$director.'&genre='.$genre; |
||
| 57 | |||
| 58 | if ((int) $category === -1) { |
||
| 59 | $catname = 'All'; |
||
| 60 | } else { |
||
| 61 | $cdata = Category::find($category); |
||
| 62 | if ($cdata !== null) { |
||
| 63 | $catname = $cdata->title; |
||
| 64 | } else { |
||
| 65 | $catname = 'All'; |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | // Build order by URLs |
||
| 70 | $orderByUrls = []; |
||
| 71 | foreach ($ordering as $ordertype) { |
||
| 72 | $orderByUrls['orderby'.$ordertype] = url('/XXX/'.($id ?: 'All').'?t='.$category.$browseby_link.'&ob='.$ordertype.'&offset=0'); |
||
| 73 | } |
||
| 74 | |||
| 75 | $this->viewData = array_merge($this->viewData, [ |
||
| 76 | 'catlist' => $mtmp, |
||
| 77 | 'category' => $category, |
||
| 78 | 'categorytitle' => $id, |
||
| 79 | 'catname' => $catname, |
||
| 80 | 'title' => stripslashes($title), |
||
| 81 | 'actors' => $actors, |
||
| 82 | 'director' => $director, |
||
| 83 | 'genres' => $genres, |
||
| 84 | 'genre' => $genre, |
||
| 85 | 'results' => $results, |
||
| 86 | 'lastvisit' => $this->userdata['lastlogin'] ?? null, |
||
| 87 | 'meta_title' => 'Browse XXX', |
||
| 88 | 'meta_keywords' => 'browse,xxx,nzb,description,details', |
||
| 89 | 'meta_description' => 'Browse for XXX Movies', |
||
| 90 | ], $orderByUrls); |
||
| 91 | |||
| 92 | return view('xxx.index', $this->viewData); |
||
| 93 | } |
||
| 95 |