AdultController::show()   F
last analyzed

Complexity

Conditions 23
Paths > 20000

Size

Total Lines 95
Code Lines 66

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 66
dl 0
loc 95
rs 0
c 0
b 0
f 0
cc 23
nc 1179648
nop 2

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Category;
6
use Blacklight\XXX;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\Arr;
9
10
class AdultController extends BasePageController
11
{
12
    /**
13
     * @throws \Exception
14
     */
15
    public function show(Request $request, string $id = ''): void
16
    {
17
        $this->setPreferences();
18
        $adult = new XXX;
19
20
        $moviecats = Category::getChildren(Category::XXX_ROOT);
21
        $mtmp = [];
22
        foreach ($moviecats as $mcat) {
23
            $mtmp[] =
24
                [
25
                    'id' => $mcat->id,
26
                    'title' => $mcat->title,
27
                ];
28
        }
29
        $category = $request->has('t') ? $request->input('t') : Category::XXX_ROOT;
30
        if ($id && \in_array($id, Arr::pluck($mtmp, 'title'), false)) {
31
            $cat = Category::query()
32
                ->where('title', $id)
33
                ->where('root_categories_id', '=', Category::XXX_ROOT)
34
                ->first(['id']);
35
            $category = $cat !== null ? $cat['id'] : Category::XXX_ROOT;
36
        }
37
        $catarray = [];
38
        $catarray[] = $category;
39
40
        $this->smarty->assign('catlist', $mtmp);
41
        $this->smarty->assign('category', $category);
42
        $this->smarty->assign('categorytitle', $id);
43
44
        $ordering = $adult->getXXXOrdering();
45
        $orderby = $request->has('ob') && \in_array($request->input('ob'), $ordering, false) ? $request->input('ob') : '';
46
47
        $movies = [];
48
        $page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1;
49
        $offset = ($page - 1) * config('nntmux.items_per_cover_page');
50
        $rslt = $adult->getXXXRange($page, $catarray, $offset, config('nntmux.items_per_cover_page'), $orderby, -1, $this->userdata['categoryexclusions']);
51
        $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_cover_page'), $page, $request->url(), $request->query());
52
        foreach ($results as $result) {
53
            $result->genre = makeFieldLinks((array) $result, 'genre', 'xxx');
54
            $result->actors = makeFieldLinks((array) $result, 'actors', 'xxx');
55
            $result->director = makeFieldLinks((array) $result, 'director', 'xxx');
56
57
            $movies[] = $result;
58
        }
59
60
        $title = ($request->has('title') && ! empty($request->input('title'))) ? stripslashes($request->input('title')) : '';
61
        $this->smarty->assign('title', stripslashes($title));
62
63
        $actors = ($request->has('actors') && ! empty($request->input('actors'))) ? stripslashes($request->input('actors')) : '';
64
        $this->smarty->assign('actors', $actors);
65
66
        $director = ($request->has('director') && ! empty($request->input('director'))) ? stripslashes($request->input('director')) : '';
67
        $this->smarty->assign('director', $director);
68
69
        $genres = $adult->getAllGenres(true);
70
        $genre = ($request->has('genre') && \in_array($request->input('genre'), $genres, false)) ? $request->input('genre') : '';
71
        $this->smarty->assign('genres', $genres);
72
        $this->smarty->assign('genre', $genre);
73
74
        $browseby_link = '&amp;title='.$title.'&amp;actors='.$actors.'&amp;director='.$director.'&amp;genre='.$genre;
75
76
        if ((int) $category === -1) {
77
            $this->smarty->assign('catname', 'All');
78
        } else {
79
            $cdata = Category::find($category);
80
            if ($cdata !== null) {
81
                $this->smarty->assign('catname', $cdata);
82
            } else {
83
                $this->smarty->assign('catname', 'All');
84
            }
85
        }
86
87
        foreach ($ordering as $ordertype) {
88
            $this->smarty->assign('orderby'.$ordertype, url('/xxx?t='.$category.$browseby_link.'&amp;ob='.$ordertype.'&amp;offset=0'));
89
        }
90
91
        $this->smarty->assign(
92
            [
93
                'resultsadd' => $movies,
94
                'results' => $results,
95
                'covgroup' => 'xxx',
96
            ]
97
        );
98
99
        $meta_title = 'Browse XXX';
100
        $meta_keywords = 'browse,xxx,nzb,description,details';
101
        $meta_description = 'Browse for XXX Movies';
102
103
        if ($request->has('id')) {
104
            $content = $this->smarty->fetch('viewxxxfull.tpl');
105
        } else {
106
            $content = $this->smarty->fetch('xxx.tpl');
107
        }
108
        $this->smarty->assign(compact('content', 'meta_title', 'meta_keywords', 'meta_description'));
109
        $this->pagerender();
110
    }
111
}
112