Issues (864)

app/Http/Controllers/DetailsController.php (5 issues)

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 App\Services\Releases\ReleaseSearchService;
16
use Blacklight\AniDB;
17
use Blacklight\Books;
18
use Blacklight\Console;
19
use Blacklight\Games;
0 ignored issues
show
The type Blacklight\Games was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Blacklight\Movie;
21
use Blacklight\Music;
22
use Blacklight\ReleaseExtra;
23
use Blacklight\XXX;
24
use Illuminate\Http\Request;
25
26
class DetailsController extends BasePageController
27
{
28
    private ReleaseSearchService $releaseSearchService;
29
30
    public function __construct(ReleaseSearchService $releaseSearchService)
31
    {
32
        parent::__construct();
33
        $this->releaseSearchService = $releaseSearchService;
34
    }
35
36
    public function show(Request $request, string $guid)
37
    {
38
        if ($guid !== null) {
0 ignored issues
show
The condition $guid !== null is always true.
Loading history...
39
            $re = new ReleaseExtra;
40
            $data = Release::getByGuid($guid);
41
            $releaseRegex = '';
42
            if (! empty($data)) {
43
                $releaseRegex = ReleaseRegex::query()->where('releases_id', '=', $data['id'])->first();
44
            }
45
46
            if (! $data) {
47
                return redirect()->back();
48
            }
49
50
            if ($this->isPostBack($request)) {
51
                ReleaseComment::addComment($data['id'], $data['gid'], $request->input('txtAddComment'), $this->userdata->id, $request->ip());
52
53
                return redirect()->route('details', ['guid' => $guid])->with('success', 'Comment posted successfully!');
54
            }
55
56
            $nfoData = ReleaseNfo::getReleaseNfo($data['id']);
57
            $nfo = $nfoData ? $nfoData->nfo : null;
58
            $reVideo = $re->getVideo($data['id']);
59
            $reAudio = $re->getAudio($data['id']);
60
            $reSubs = $re->getSubs($data['id']);
61
            $comments = ReleaseComment::getComments($data['id']);
62
            $similars = $this->releaseSearchService->searchSimilar($data['id'], $data['searchname'], $this->userdata->categoryexclusions);
63
            $failed = DnzbFailure::getFailedCount($data['id']);
64
            $downloadedBy = UserDownload::query()->with('user')->where('releases_id', $data['id'])->get(['users_id']);
65
66
            $showInfo = '';
67
            if ($data['videos_id'] > 0) {
68
                $showInfo = Video::getByVideoID($data['videos_id']);
69
            }
70
71
            $mov = '';
72
            if ($data['imdbid'] !== '' && $data['imdbid'] !== 0000000) {
73
                $movie = new Movie(['Settings' => $this->settings]);
0 ignored issues
show
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

73
                $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...
74
                $mov = $movie->getMovieInfo($data['imdbid']);
75
                if (! empty($mov['title'])) {
76
                    $mov['title'] = str_replace(['/', '\\'], '', $mov['title']);
77
                    $mov['actors'] = makeFieldLinks($mov, 'actors', 'movies');
78
                    $mov['genre'] = makeFieldLinks($mov, 'genre', 'movies');
79
                    $mov['director'] = makeFieldLinks($mov, 'director', 'movies');
80
                    if (Settings::settingValue('trailers_display')) {
81
                        $trailer = empty($mov['trailer']) || $mov['trailer'] === '' ? $movie->getTrailer($data['imdbid']) : $mov['trailer'];
82
                        if ($trailer) {
83
                            $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
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

83
                            $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...
84
                        }
85
                    }
86
                }
87
            }
88
89
            $xxx = '';
90
            if ($data['xxxinfo_id'] !== '' && $data['xxxinfo_id'] !== 0) {
91
                $x = new XXX;
92
                $xxx = $x->getXXXInfo($data['xxxinfo_id']);
93
94
                if (isset($xxx['trailers'])) {
95
                    $xxx['trailers'] = $x->insertSwf($xxx['classused'], $xxx['trailers']);
96
                }
97
98
                if ($xxx && isset($xxx['title'])) {
99
                    $xxx['title'] = str_replace(['/', '\\'], '', $xxx['title']);
100
                    $xxx['actors'] = makeFieldLinks($xxx, 'actors', 'xxx');
101
                    $xxx['genre'] = makeFieldLinks($xxx, 'genre', 'xxx');
102
                    $xxx['director'] = makeFieldLinks($xxx, 'director', 'xxx');
103
                } else {
104
                    $xxx = false;
105
                }
106
            }
107
108
            $game = '';
109
            if ($data['gamesinfo_id'] !== '') {
110
                $game = (new Games)->getGamesInfoById($data['gamesinfo_id']);
111
            }
112
113
            $mus = '';
114
            if ($data['musicinfo_id'] !== '') {
115
                $mus = (new Music)->getMusicInfo($data['musicinfo_id']);
116
            }
117
118
            $book = '';
119
            if ($data['bookinfo_id'] !== '') {
120
                $book = (new Books)->getBookInfo($data['bookinfo_id']);
121
            }
122
123
            $con = '';
124
            if ($data['consoleinfo_id'] !== '') {
125
                $con = (new Console)->getConsoleInfo($data['consoleinfo_id']);
126
            }
127
128
            $AniDBAPIArray = '';
129
            if ($data['anidbid'] > 0) {
130
                $AniDBAPIArray = (new AniDB)->getAnimeInfo($data['anidbid']);
131
132
                // If we have anilist_id but missing details, fetch from AniList
133
                if ($AniDBAPIArray && !empty($AniDBAPIArray->anilist_id)) {
134
                    $anilistId = is_object($AniDBAPIArray) ? $AniDBAPIArray->anilist_id : ($AniDBAPIArray['anilist_id'] ?? null);
135
                    if ($anilistId && (empty($AniDBAPIArray->country) && empty($AniDBAPIArray->media_type))) {
136
                        // Fetch fresh data from AniList if country/media_type is missing
137
                        try {
138
                            $palist = new \Blacklight\PopulateAniList;
139
                            $palist->populateTable('info', $anilistId);
140
                            // Refresh the data
141
                            $AniDBAPIArray = (new AniDB)->getAnimeInfo($data['anidbid']);
142
                        } catch (\Exception $e) {
143
                            // Silently fail, use existing data
144
                        }
145
                    }
146
                }
147
            }
148
149
            $pre = Predb::getForRelease($data['predb_id']);
150
151
            $releasefiles = ReleaseFile::getReleaseFiles($data['id']);
152
153
            $this->viewData = array_merge($this->viewData, [
154
                'releasefiles' => $releasefiles,
155
                'release' => $data,
156
                'reVideo' => $reVideo,
157
                'reAudio' => $reAudio,
158
                'reSubs' => $reSubs,
159
                'nfo' => $nfo,
160
                'show' => $showInfo,
161
                'movie' => $mov,
162
                'xxx' => $xxx,
163
                'anidb' => $AniDBAPIArray,
164
                'music' => $mus,
165
                'con' => $con,
166
                'game' => $game,
167
                'book' => $book,
168
                'predb' => $pre,
169
                'comments' => $comments,
170
                'files' => $releasefiles,
171
                'searchname' => getSimilarName($data['searchname']),
172
                'similars' => $similars !== false ? $similars : [],
0 ignored issues
show
The condition $similars !== false is always true.
Loading history...
173
                'privateprofiles' => config('nntmux_settings.private_profiles'),
174
                'failed' => $failed,
175
                'regex' => $releaseRegex,
176
                'downloadedby' => $downloadedBy,
177
                'meta_title' => 'View NZB',
178
                'meta_keywords' => 'view,nzb,description,details',
179
                'meta_description' => 'View NZB for '.$data['searchname'],
180
            ]);
181
182
            return view('details.index', $this->viewData);
183
        }
184
185
        return redirect()->back()->with('error', 'Release not found');
186
    }
187
}
188