GamesController   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 17
eloc 52
dl 0
loc 76
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
F show() 0 71 17
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Category;
6
use Blacklight\Games;
7
use Blacklight\Genres;
8
use Illuminate\Http\Request;
9
10
class GamesController extends BasePageController
11
{
12
    /**
13
     * @throws \Exception
14
     */
15
    public function show(Request $request): void
16
    {
17
        $this->setPreferences();
18
        $games = new Games(['Settings' => $this->settings]);
0 ignored issues
show
Unused Code introduced by
The call to Blacklight\Games::__construct() has too many arguments starting with array('Settings' => $this->settings). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
        $games = /** @scrutinizer ignore-call */ new Games(['Settings' => $this->settings]);

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.

Loading history...
19
        $gen = new Genres(['Settings' => $this->settings]);
0 ignored issues
show
Unused Code introduced by
The call to Blacklight\Genres::__construct() has too many arguments starting with array('Settings' => $this->settings). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
        $gen = /** @scrutinizer ignore-call */ new Genres(['Settings' => $this->settings]);

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.

Loading history...
20
21
        $concats = Category::getChildren(Category::PC_ROOT);
22
        $ctmp = [];
23
        foreach ($concats as $ccat) {
24
            $ctmp[$ccat['id']] = $ccat;
25
        }
26
        $category = Category::PC_GAMES;
27
        if ($request->has('t') && array_key_exists($request->input('t'), $ctmp)) {
28
            $category = $request->input('t') + 0;
29
        }
30
31
        $catarray = [];
32
        $catarray[] = $category;
33
34
        $this->smarty->assign('catlist', $ctmp);
35
        $this->smarty->assign('category', $category);
36
37
        $page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1;
38
        $ordering = $games->getGamesOrdering();
39
        $orderby = $request->has('ob') && \in_array($request->input('ob'), $ordering, false) ? $request->input('ob') : '';
40
        $offset = ($page - 1) * config('nntmux.items_per_cover_page');
41
        $rslt = $games->getGamesRange($page, $catarray, $offset, config('nntmux.items_per_cover_page'), $orderby, '', $this->userdata->categoryexclusions);
0 ignored issues
show
Bug introduced by
The property categoryexclusions does not seem to exist on App\Models\User.
Loading history...
42
        $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_cover_page'), $page, $request->url(), $request->query());
43
44
        $title = ($request->has('title') && ! empty($request->input('title'))) ? stripslashes($request->input('title')) : '';
45
        $this->smarty->assign('title', $title);
46
47
        $genres = $gen->getGenres(Genres::GAME_TYPE, true);
48
        $tmpgnr = [];
49
        foreach ($genres as $gn) {
50
            $tmpgnr[$gn->id] = $gn->title;
51
        }
52
53
        $years = range(1903, date('Y') + 1);
54
        rsort($years);
55
        $year = ($request->has('year') && \in_array($request->input('year'), $years, false)) ? $request->input('year') : '';
56
        $this->smarty->assign('years', $years);
57
        $this->smarty->assign('year', $year);
58
59
        $genre = ($request->has('genre') && array_key_exists($request->input('genre'), $tmpgnr)) ? $request->input('genre') : '';
60
        $this->smarty->assign('genres', $genres);
61
        $this->smarty->assign('genre', $genre);
62
63
        if ((int) $category === -1) {
64
            $this->smarty->assign('catname', 'All');
65
        } else {
66
            $cdata = Category::find($category);
67
            if ($cdata !== null) {
68
                $this->smarty->assign('catname', $cdata);
69
            } else {
70
                $this->smarty->assign('catname', 'All');
71
            }
72
        }
73
74
        $this->smarty->assign('results', $results);
75
        $this->smarty->assign('covgroup', 'games');
76
77
        $meta_title = 'Browse Games';
78
        $meta_keywords = 'browse,nzb,games,description,details';
79
        $meta_description = 'Browse for Games';
80
81
        $content = $this->smarty->fetch('games.tpl');
82
        $this->smarty->assign(
83
            compact('content', 'meta_title', 'meta_keywords', 'meta_description')
84
        );
85
        $this->pagerender();
86
    }
87
}
88