fix: types on torrent meta trait

This commit is contained in:
Roardom
2024-05-26 14:47:52 +00:00
parent ef047ef3a4
commit 184b57a68a
2 changed files with 29 additions and 54 deletions
+29 -9
View File
@@ -18,11 +18,22 @@ namespace App\Traits;
use App\Models\Movie;
use App\Models\Tv;
use JsonException;
use MarcReichel\IGDBLaravel\Models\Game;
use ReflectionException;
trait TorrentMeta
{
public function scopeMeta($torrents): \Illuminate\Pagination\LengthAwarePaginator|\Illuminate\Database\Eloquent\Collection
/**
* @param \Illuminate\Database\Eloquent\Collection<int, \App\Models\Torrent>|\Illuminate\Pagination\CursorPaginator<\App\Models\Torrent>|\Illuminate\Pagination\LengthAwarePaginator<\App\Models\Torrent> $torrents
*
* @throws \MarcReichel\IGDBLaravel\Exceptions\MissingEndpointException
* @throws \MarcReichel\IGDBLaravel\Exceptions\InvalidParamsException
* @throws ReflectionException
* @throws JsonException
* @return ($torrents is \Illuminate\Database\Eloquent\Collection<int, \App\Models\Torrent> ? \Illuminate\Support\Collection<int, \App\Models\Torrent> : ($torrents is \Illuminate\Pagination\CursorPaginator<\App\Models\Torrent> ? \Illuminate\Pagination\CursorPaginator<\App\Models\Torrent> : \Illuminate\Pagination\LengthAwarePaginator<\App\Models\Torrent>))
*/
public function scopeMeta(\Illuminate\Database\Eloquent\Collection|\Illuminate\Pagination\CursorPaginator|\Illuminate\Pagination\LengthAwarePaginator $torrents): \Illuminate\Support\Collection|\Illuminate\Pagination\CursorPaginator|\Illuminate\Pagination\LengthAwarePaginator
{
$movieIds = $torrents->where('meta', '=', 'movie')->pluck('tmdb');
$tvIds = $torrents->where('meta', '=', 'tv')->pluck('tmdb');
@@ -36,15 +47,24 @@ trait TorrentMeta
$games[$gameId] = Game::with(['cover' => ['url', 'image_id'], 'genres' => ['name']])->find($gameId);
}
return $torrents->map(function ($torrent) use ($movies, $tv, $games) {
$torrent->meta = match ($torrent->meta) {
'movie' => $movies[$torrent->tmdb] ?? null,
'tv' => $tv[$torrent->tmdb] ?? null,
'game' => $games[$torrent->igdb] ?? null,
default => null,
};
$setRelation = function ($torrent) use ($movies, $tv, $games) {
$torrent->setRelation(
'meta',
match ($torrent->meta) {
'movie' => $movies[$torrent->tmdb] ?? null,
'tv' => $tv[$torrent->tmdb] ?? null,
'game' => $games[$torrent->igdb] ?? null,
default => null,
},
);
return $torrent;
});
};
if ($torrents instanceof \Illuminate\Database\Eloquent\Collection) {
return $torrents->map($setRelation);
}
return $torrents->through($setRelation);
}
}
-45
View File
@@ -460,21 +460,6 @@ parameters:
count: 1
path: app/Http/Controllers/API/TorrentController.php
-
message: "#^Method App\\\\Http\\\\Controllers\\\\API\\\\TorrentController\\:\\:scopeMeta\\(\\) has parameter \\$torrents with no type specified\\.$#"
count: 1
path: app/Http/Controllers/API/TorrentController.php
-
message: "#^Method App\\\\Http\\\\Controllers\\\\API\\\\TorrentController\\:\\:scopeMeta\\(\\) return type with generic class Illuminate\\\\Database\\\\Eloquent\\\\Collection does not specify its types\\: TKey, TModel$#"
count: 1
path: app/Http/Controllers/API/TorrentController.php
-
message: "#^Method App\\\\Http\\\\Controllers\\\\API\\\\TorrentController\\:\\:scopeMeta\\(\\) return type with generic class Illuminate\\\\Pagination\\\\LengthAwarePaginator does not specify its types\\: TValue$#"
count: 1
path: app/Http/Controllers/API/TorrentController.php
-
message: "#^Parameter \\#1 \\$inputFile of static method App\\\\Helpers\\\\TorrentTools\\:\\:getNfo\\(\\) expects Illuminate\\\\Http\\\\UploadedFile\\|null, array\\<int, Illuminate\\\\Http\\\\UploadedFile\\>\\|Illuminate\\\\Http\\\\UploadedFile\\|null given\\.$#"
count: 1
@@ -960,21 +945,6 @@ parameters:
count: 2
path: app/Http/Livewire/Top10.php
-
message: "#^Method App\\\\Http\\\\Livewire\\\\TopTorrents\\:\\:scopeMeta\\(\\) has parameter \\$torrents with no type specified\\.$#"
count: 1
path: app/Http/Livewire/TopTorrents.php
-
message: "#^Method App\\\\Http\\\\Livewire\\\\TopTorrents\\:\\:scopeMeta\\(\\) return type with generic class Illuminate\\\\Database\\\\Eloquent\\\\Collection does not specify its types\\: TKey, TModel$#"
count: 1
path: app/Http/Livewire/TopTorrents.php
-
message: "#^Method App\\\\Http\\\\Livewire\\\\TopTorrents\\:\\:scopeMeta\\(\\) return type with generic class Illuminate\\\\Pagination\\\\LengthAwarePaginator does not specify its types\\: TValue$#"
count: 1
path: app/Http/Livewire/TopTorrents.php
-
message: "#^Access to an undefined property App\\\\Models\\\\Movie\\|Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\), mixed\\>\\:\\:\\$category_id\\.$#"
count: 1
@@ -1010,21 +980,6 @@ parameters:
count: 1
path: app/Http/Livewire/TorrentSearch.php
-
message: "#^Method App\\\\Http\\\\Livewire\\\\TorrentSearch\\:\\:scopeMeta\\(\\) has parameter \\$torrents with no type specified\\.$#"
count: 1
path: app/Http/Livewire/TorrentSearch.php
-
message: "#^Method App\\\\Http\\\\Livewire\\\\TorrentSearch\\:\\:scopeMeta\\(\\) return type with generic class Illuminate\\\\Database\\\\Eloquent\\\\Collection does not specify its types\\: TKey, TModel$#"
count: 1
path: app/Http/Livewire/TorrentSearch.php
-
message: "#^Method App\\\\Http\\\\Livewire\\\\TorrentSearch\\:\\:scopeMeta\\(\\) return type with generic class Illuminate\\\\Pagination\\\\LengthAwarePaginator does not specify its types\\: TValue$#"
count: 1
path: app/Http/Livewire/TorrentSearch.php
-
message: "#^Parameter \\#1 \\$boolean of function abort_unless expects bool, int given\\.$#"
count: 3