MusicController   A
last analyzed

Complexity

Total Complexity 22

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 22
eloc 67
dl 0
loc 102
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
F show() 0 97 22
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Category;
6
use Blacklight\Genres;
7
use Blacklight\Music;
8
use Illuminate\Http\Request;
9
use Illuminate\Support\Arr;
10
11
class MusicController extends BasePageController
12
{
13
    /**
14
     * @throws \Exception
15
     */
16
    public function show(Request $request, string $id = ''): void
17
    {
18
        $this->setPreferences();
19
        $music = new Music(['Settings' => $this->settings]);
0 ignored issues
show
Unused Code introduced by
The call to Blacklight\Music::__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
        $music = /** @scrutinizer ignore-call */ new Music(['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
        $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

20
        $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...
21
22
        $musiccats = Category::getChildren(Category::MUSIC_ROOT);
23
        $mtmp = [];
24
        foreach ($musiccats as $mcat) {
25
            $mtmp[] =
26
                [
27
                    'id' => $mcat->id,
28
                    'title' => $mcat->title,
29
                ];
30
        }
31
32
        $category = $request->has('t') ? $request->input('t') : Category::MUSIC_ROOT;
33
        if ($id && \in_array($id, Arr::pluck($mtmp, 'title'), false)) {
34
            $cat = Category::query()
35
                ->where('title', $id)
36
                ->where('root_categories_id', '=', Category::MUSIC_ROOT)
37
                ->first(['id']);
38
            $category = $cat !== null ? $cat['id'] : Category::MUSIC_ROOT;
39
        }
40
41
        $catarray = [];
42
        $catarray[] = $category;
43
44
        $this->smarty->assign('catlist', $mtmp);
45
        $this->smarty->assign('category', $category);
46
        $this->smarty->assign('categorytitle', $id);
47
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
        $ordering = $music->getMusicOrdering();
51
        $orderby = $request->has('ob') && \in_array($request->input('ob'), $ordering, false) ? $request->input('ob') : '';
52
53
        $musics = [];
54
        $rslt = $music->getMusicRange($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...
55
        $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_cover_page'), $page, $request->url(), $request->query());
56
57
        $artist = ($request->has('artist') && ! empty($request->input('artist'))) ? stripslashes($request->input('artist')) : '';
58
        $this->smarty->assign('artist', $artist);
59
60
        $title = ($request->has('title') && ! empty($request->input('title'))) ? stripslashes($request->input('title')) : '';
61
        $this->smarty->assign('title', $title);
62
63
        $genres = $gen->getGenres(Genres::MUSIC_TYPE, true);
64
        $tmpgnr = [];
65
        foreach ($genres as $gn) {
66
            $tmpgnr[$gn->id] = $gn->title;
67
        }
68
69
        foreach ($results as $result) {
70
            $res = $result;
71
            $result->genre = $tmpgnr[$res->genres_id];
72
            $musics[] = $result;
73
        }
74
75
        $genre = ($request->has('genre') && array_key_exists($request->input('genre'), $tmpgnr)) ? $request->input('genre') : '';
76
        $this->smarty->assign('genres', $genres);
77
        $this->smarty->assign('genre', $genre);
78
79
        $years = range(1950, date('Y') + 1);
80
        rsort($years);
81
        $year = ($request->has('year') && \in_array($request->input('year'), $years, false)) ? $request->input('year') : '';
82
        $this->smarty->assign('years', $years);
83
        $this->smarty->assign('year', $year);
84
85
        if ((int) $category === -1) {
86
            $this->smarty->assign('catname', 'All');
87
        } else {
88
            $cdata = Category::find($category);
89
            if ($cdata !== null) {
90
                $this->smarty->assign('catname', $cdata);
91
            } else {
92
                $this->smarty->assign('catname', 'All');
93
            }
94
        }
95
96
        $this->smarty->assign(
97
            [
98
                'resultsadd' => $musics,
99
                'results' => $results,
100
                'covgroup' => 'music',
101
            ]
102
        );
103
104
        $meta_title = 'Browse Albums';
105
        $meta_keywords = 'browse,nzb,albums,description,details';
106
        $meta_description = 'Browse for Albums';
107
108
        $content = $this->smarty->fetch('music.tpl');
109
110
        $this->smarty->assign(compact('content', 'meta_title', 'meta_keywords', 'meta_description'));
111
112
        $this->pagerender();
113
    }
114
}
115