Issues (435)

app/Http/Controllers/MusicController.php (3 issues)

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 = '')
17
    {
18
        $music = new Music(['Settings' => $this->settings]);
0 ignored issues
show
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

18
        $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...
19
        $gen = new Genres(['Settings' => $this->settings]);
0 ignored issues
show
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
        $musiccats = Category::getChildren(Category::MUSIC_ROOT);
22
        $mtmp = [];
23
        foreach ($musiccats as $mcat) {
24
            $mtmp[] =
25
                [
26
                    'id' => $mcat->id,
27
                    'title' => $mcat->title,
28
                ];
29
        }
30
31
        $category = $request->has('t') ? $request->input('t') : Category::MUSIC_ROOT;
32
        if ($id && \in_array($id, Arr::pluck($mtmp, 'title'), false)) {
33
            $cat = Category::query()
34
                ->where('title', $id)
35
                ->where('root_categories_id', '=', Category::MUSIC_ROOT)
36
                ->first(['id']);
37
            $category = $cat !== null ? $cat['id'] : Category::MUSIC_ROOT;
38
        }
39
40
        $catarray = [];
41
        $catarray[] = $category;
42
43
        $page = $request->has('page') && is_numeric($request->input('page')) ? $request->input('page') : 1;
44
        $offset = ($page - 1) * config('nntmux.items_per_cover_page');
45
        $ordering = $music->getMusicOrdering();
46
        $orderby = $request->has('ob') && \in_array($request->input('ob'), $ordering, false) ? $request->input('ob') : '';
47
48
        $musics = [];
49
        $rslt = $music->getMusicRange($page, $catarray, $offset, config('nntmux.items_per_cover_page'), $orderby, $this->userdata->categoryexclusions);
0 ignored issues
show
The property categoryexclusions does not seem to exist on App\Models\User.
Loading history...
50
        $results = $this->paginate($rslt ?? [], $rslt[0]->_totalcount ?? 0, config('nntmux.items_per_cover_page'), $page, $request->url(), $request->query());
51
52
        $artist = ($request->has('artist') && ! empty($request->input('artist'))) ? stripslashes($request->input('artist')) : '';
53
54
        $title = ($request->has('title') && ! empty($request->input('title'))) ? stripslashes($request->input('title')) : '';
55
56
        $genres = $gen->getGenres(Genres::MUSIC_TYPE, true);
57
        $tmpgnr = [];
58
        foreach ($genres as $gn) {
59
            $tmpgnr[$gn->id] = $gn->title;
60
        }
61
62
        foreach ($results as $result) {
63
            $res = $result;
64
            $result->genre = $tmpgnr[$res->genres_id];
65
            $musics[] = $result;
66
        }
67
68
        $genre = ($request->has('genre') && array_key_exists($request->input('genre'), $tmpgnr)) ? $request->input('genre') : '';
69
70
        $years = range(1950, date('Y') + 1);
71
        rsort($years);
72
        $year = ($request->has('year') && \in_array($request->input('year'), $years, false)) ? $request->input('year') : '';
73
74
        if ((int) $category === -1) {
75
            $catname = 'All';
76
        } else {
77
            $cdata = Category::find($category);
78
            if ($cdata !== null) {
79
                $catname = $cdata->title;
80
            } else {
81
                $catname = 'All';
82
            }
83
        }
84
85
        // Build order by URLs
86
        $orderByUrls = [];
87
        foreach ($ordering as $orderType) {
88
            $orderByUrls['orderby'.$orderType] = url('music/'.($id ?: 'All').'?ob='.$orderType);
89
        }
90
91
        $this->viewData = array_merge($this->viewData, [
92
            'catlist' => $mtmp,
93
            'category' => $category,
94
            'categorytitle' => $id,
95
            'catname' => $catname,
96
            'artist' => $artist,
97
            'title' => $title,
98
            'genres' => $genres,
99
            'genre' => $genre,
100
            'years' => $years,
101
            'year' => $year,
102
            'resultsadd' => $musics,
103
            'results' => $results,
104
            'covgroup' => 'music',
105
            'meta_title' => 'Browse Albums',
106
            'meta_keywords' => 'browse,nzb,albums,description,details',
107
            'meta_description' => 'Browse for Albums',
108
        ], $orderByUrls);
109
110
        return view('music.index', $this->viewData);
111
    }
112
}
113