DetailsController   A
last analyzed

Complexity

Total Complexity 24

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 24
eloc 95
dl 0
loc 133
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
F show() 0 131 24
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\DnzbFailure;
6
use App\Models\Predb;
7
use App\Models\Release;
8
use App\Models\ReleaseComment;
9
use App\Models\ReleaseFile;
10
use App\Models\ReleaseNfo;
11
use App\Models\ReleaseRegex;
12
use App\Models\Settings;
13
use App\Models\UserDownload;
14
use App\Models\Video;
15
use Blacklight\AniDB;
16
use Blacklight\Books;
17
use Blacklight\Console;
18
use Blacklight\Games;
19
use Blacklight\Movie;
20
use Blacklight\Music;
21
use Blacklight\ReleaseExtra;
22
use Blacklight\Releases;
23
use Blacklight\XXX;
24
use Illuminate\Http\Request;
25
26
class DetailsController extends BasePageController
27
{
28
    public function show(Request $request, string $guid)
29
    {
30
        $this->setPreferences();
31
32
        if ($guid !== null) {
0 ignored issues
show
introduced by
The condition $guid !== null is always true.
Loading history...
33
            $releases = new Releases;
34
            $re = new ReleaseExtra;
35
            $data = Release::getByGuid($guid);
36
            $releaseRegex = '';
37
            if (! empty($data)) {
38
                $releaseRegex = ReleaseRegex::query()->where('releases_id', '=', $data['id'])->first();
39
            }
40
41
            if (! $data) {
42
                return redirect()->back();
43
            }
44
45
            if ($this->isPostBack($request)) {
46
                ReleaseComment::addComment($data['id'], $data['gid'], $request->input('txtAddComment'), $this->userdata->id, $request->ip());
47
            }
48
49
            $nfo = ReleaseNfo::getReleaseNfo($data['id']);
50
            $reVideo = $re->getVideo($data['id']);
51
            $reAudio = $re->getAudio($data['id']);
52
            $reSubs = $re->getSubs($data['id']);
53
            $comments = ReleaseComment::getComments($data['id']);
54
            $similars = $releases->searchSimilar($data['id'], $data['searchname'], $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
            $failed = DnzbFailure::getFailedCount($data['id']);
56
            $downloadedBy = UserDownload::query()->with('user')->where('releases_id', $data['id'])->get(['users_id']);
57
58
            $showInfo = '';
59
            if ($data['videos_id'] > 0) {
60
                $showInfo = Video::getByVideoID($data['videos_id']);
61
            }
62
63
            $mov = '';
64
            if ($data['imdbid'] !== '' && $data['imdbid'] !== 0000000) {
65
                $movie = new Movie(['Settings' => $this->settings]);
0 ignored issues
show
Unused Code introduced by
The call to Blacklight\Movie::__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

65
                $movie = /** @scrutinizer ignore-call */ new Movie(['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...
66
                $mov = $movie->getMovieInfo($data['imdbid']);
67
                if (! empty($mov['title'])) {
68
                    $mov['title'] = str_replace(['/', '\\'], '', $mov['title']);
69
                    $mov['actors'] = makeFieldLinks($mov, 'actors', 'movies');
70
                    $mov['genre'] = makeFieldLinks($mov, 'genre', 'movies');
71
                    $mov['director'] = makeFieldLinks($mov, 'director', 'movies');
72
                    if (Settings::settingValue('trailers_display')) {
73
                        $trailer = empty($mov['trailer']) || $mov['trailer'] === '' ? $movie->getTrailer($data['imdbid']) : $mov['trailer'];
74
                        if ($trailer) {
75
                            $mov['trailer'] = sprintf('<iframe width="%d" height="%d" src="%s"></iframe>', Settings::settingValue('trailers_size_x'), Settings::settingValue('trailers_size_y'), $trailer);
0 ignored issues
show
Bug introduced by
It seems like $trailer can also be of type true; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

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

75
                            $mov['trailer'] = sprintf('<iframe width="%d" height="%d" src="%s"></iframe>', Settings::settingValue('trailers_size_x'), Settings::settingValue('trailers_size_y'), /** @scrutinizer ignore-type */ $trailer);
Loading history...
76
                        }
77
                    }
78
                }
79
            }
80
81
            $xxx = '';
82
            if ($data['xxxinfo_id'] !== '' && $data['xxxinfo_id'] !== 0) {
83
                $x = new XXX;
84
                $xxx = $x->getXXXInfo($data['xxxinfo_id']);
85
86
                if (isset($xxx['trailers'])) {
87
                    $xxx['trailers'] = $x->insertSwf($xxx['classused'], $xxx['trailers']);
88
                }
89
90
                if ($xxx && isset($xxx['title'])) {
91
                    $xxx['title'] = str_replace(['/', '\\'], '', $xxx['title']);
92
                    $xxx['actors'] = makeFieldLinks($xxx, 'actors', 'xxx');
93
                    $xxx['genre'] = makeFieldLinks($xxx, 'genre', 'xxx');
94
                    $xxx['director'] = makeFieldLinks($xxx, 'director', 'xxx');
95
                } else {
96
                    $xxx = false;
97
                }
98
            }
99
100
            $game = '';
101
            if ($data['gamesinfo_id'] !== '') {
102
                $game = (new Games)->getGamesInfoById($data['gamesinfo_id']);
103
            }
104
105
            $mus = '';
106
            if ($data['musicinfo_id'] !== '') {
107
                $mus = (new Music)->getMusicInfo($data['musicinfo_id']);
108
            }
109
110
            $book = '';
111
            if ($data['bookinfo_id'] !== '') {
112
                $book = (new Books)->getBookInfo($data['bookinfo_id']);
113
            }
114
115
            $con = '';
116
            if ($data['consoleinfo_id'] !== '') {
117
                $con = (new Console)->getConsoleInfo($data['consoleinfo_id']);
118
            }
119
120
            $AniDBAPIArray = '';
121
            if ($data['anidbid'] > 0) {
122
                $AniDBAPIArray = (new AniDB)->getAnimeInfo($data['anidbid']);
123
            }
124
125
            $pre = Predb::getForRelease($data['predb_id']);
126
127
            $releasefiles = ReleaseFile::getReleaseFiles($data['id']);
128
129
            $this->smarty->assign('releasefiles', $releasefiles);
130
            $this->smarty->assign('release', $data);
131
            $this->smarty->assign('reVideo', $reVideo);
132
            $this->smarty->assign('reAudio', $reAudio);
133
            $this->smarty->assign('reSubs', $reSubs);
134
            $this->smarty->assign('nfo', $nfo);
135
            $this->smarty->assign('show', $showInfo);
136
            $this->smarty->assign('movie', $mov);
137
            $this->smarty->assign('xxx', $xxx);
138
            $this->smarty->assign('anidb', $AniDBAPIArray);
139
            $this->smarty->assign('music', $mus);
140
            $this->smarty->assign('con', $con);
141
            $this->smarty->assign('game', $game);
142
            $this->smarty->assign('book', $book);
143
            $this->smarty->assign('predb', $pre);
144
            $this->smarty->assign('comments', $comments);
145
            $this->smarty->assign('searchname', getSimilarName($data['searchname']));
146
            $this->smarty->assign('similars', $similars !== false ? $similars : []);
0 ignored issues
show
introduced by
The condition $similars !== false is always true.
Loading history...
147
            $this->smarty->assign('privateprofiles', config('nntmux_settings.private_profiles'));
148
            $this->smarty->assign('failed', $failed);
149
            $this->smarty->assign('regex', $releaseRegex);
150
            $this->smarty->assign('downloadedby', $downloadedBy);
151
152
            $meta_title = 'View NZB';
153
            $meta_keywords = 'view,nzb,description,details';
154
            $meta_description = 'View NZB for'.$data['searchname'];
155
156
            $content = $this->smarty->fetch('viewnzb.tpl');
157
            $this->smarty->assign(compact('content', 'meta_title', 'meta_keywords', 'meta_description'));
158
            $this->pagerender();
159
        }
160
    }
161
}
162