From af7bb77acc2ab1049424bcf5a85b4ad633b4de8c Mon Sep 17 00:00:00 2001 From: Roardom Date: Tue, 2 Dec 2025 10:56:13 +0000 Subject: [PATCH] fix: error 500 on similar page when filter returns 0 results The similar page assumes that a torrent exists for a torrent, otherwise returning a 404. However, if a user uses the search on the similar page, and uses a search query that returns 0 torrents, the assumption that a torrent exists breaks. In this case, we now fall back to an empty array instead. --- app/Http/Livewire/SimilarTorrent.php | 9 +++------ phpstan-baseline.neon | 18 ------------------ 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/app/Http/Livewire/SimilarTorrent.php b/app/Http/Livewire/SimilarTorrent.php index 16d585ea7..a110946e3 100644 --- a/app/Http/Livewire/SimilarTorrent.php +++ b/app/Http/Livewire/SimilarTorrent.php @@ -337,12 +337,9 @@ class SimilarTorrent extends Component ->get(); return match ($this->work::class) { - /** @phpstan-ignore offsetAccess.notFound ('movie' offset exists if the torrent is a movie) */ - TmdbMovie::class => self::groupTorrents($torrents)['movie'][$this->tmdbId]['Movie'], - /** @phpstan-ignore offsetAccess.notFound ('tv' offset exists if the torrent is a tv) */ - TmdbTv::class => self::groupTorrents($torrents)['tv'][$this->tmdbId], - /** @phpstan-ignore offsetAccess.notFound ('game' offset exists if the torrent is a game) */ - IgdbGame::class => self::groupTorrents($torrents)['game'][$this->igdbId]['Game'], + TmdbMovie::class => self::groupTorrents($torrents)['movie'][$this->tmdbId]['Movie'] ?? [], + TmdbTv::class => self::groupTorrents($torrents)['tv'][$this->tmdbId] ?? [], + IgdbGame::class => self::groupTorrents($torrents)['game'][$this->igdbId]['Game'] ?? [], }; } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 28f59871c..2be496da9 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -420,24 +420,6 @@ parameters: count: 1 path: app/Http/Livewire/MissingMediaSearch.php - - - message: '#^Offset ''game'' might not exist on array\{movie\?\: non\-empty\-array\\>, category_id\: int\}\>, tv\?\: non\-empty\-array\\>, Specials\?\: non\-empty\-array\\>\>, Seasons\?\: non\-empty\-array\\>, Episodes\?\: non\-empty\-array\\>\>\}\>, category_id\: int\}\>, game\?\: non\-empty\-array\\>, category_id\: int\}\>\}\.$#' - identifier: offsetAccess.notFound - count: 1 - path: app/Http/Livewire/SimilarTorrent.php - - - - message: '#^Offset ''movie'' might not exist on array\{movie\?\: non\-empty\-array\\>, category_id\: int\}\>, tv\?\: non\-empty\-array\\>, Specials\?\: non\-empty\-array\\>\>, Seasons\?\: non\-empty\-array\\>, Episodes\?\: non\-empty\-array\\>\>\}\>, category_id\: int\}\>, game\?\: non\-empty\-array\\>, category_id\: int\}\>\}\.$#' - identifier: offsetAccess.notFound - count: 1 - path: app/Http/Livewire/SimilarTorrent.php - - - - message: '#^Offset ''tv'' might not exist on array\{movie\?\: non\-empty\-array\\>, category_id\: int\}\>, tv\?\: non\-empty\-array\\>, Specials\?\: non\-empty\-array\\>\>, Seasons\?\: non\-empty\-array\\>, Episodes\?\: non\-empty\-array\\>\>\}\>, category_id\: int\}\>, game\?\: non\-empty\-array\\>, category_id\: int\}\>\}\.$#' - identifier: offsetAccess.notFound - count: 1 - path: app/Http/Livewire/SimilarTorrent.php - - message: '#^Anonymous function should return Illuminate\\Database\\Eloquent\\Builder\ but returns Illuminate\\Database\\Eloquent\\Builder\\.$#' identifier: return.type