From f7b4a1e74220af1d0db310f17ba1294862a32393 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 23 Feb 2025 17:08:17 +0100 Subject: PHPStan more checkImplicitMixed (#7339) * PHPStan more checkImplicitMixed * Draft Entry.php * Finish Entry.php * Finish FeedDAO.php and Themes.php --- app/Models/Entry.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'app/Models/Entry.php') diff --git a/app/Models/Entry.php b/app/Models/Entry.php index fe0cf7429..2454e4831 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -65,7 +65,9 @@ class FreshRSS_Entry extends Minz_Model { } $dao['attributes'] = empty($dao['attributes']) ? [] : json_decode($dao['attributes'], true); - if (!is_array($dao['attributes'])) { + if (is_array($dao['attributes'])) { + $dao['attributes'] = array_filter($dao['attributes'], 'is_string', ARRAY_FILTER_USE_KEY); + } else { $dao['attributes'] = []; } @@ -168,7 +170,7 @@ class FreshRSS_Entry extends Minz_Model { return preg_match('/(?P[\'"])' . preg_quote($link, '/') . '(?P=delim)/', $html) == 1; } - /** @param array{'url'?:string,'length'?:int,'medium'?:string,'type'?:string} $enclosure */ + /** @param array{url?:string,length?:int,medium?:string,type?:string} $enclosure */ private static function enclosureIsImage(array $enclosure): bool { $elink = $enclosure['url'] ?? ''; $length = $enclosure['length'] ?? 0; @@ -230,15 +232,15 @@ HTML; continue; } $credits = $enclosure['credit'] ?? ''; - $description = nl2br($enclosure['description'] ?? '', true); - $length = $enclosure['length'] ?? 0; - $medium = $enclosure['medium'] ?? ''; - $mime = $enclosure['type'] ?? ''; + $description = is_string($enclosure['description'] ?? null) ? nl2br($enclosure['description'], true) : ''; + $length = is_numeric($enclosure['length'] ?? null) ? (int)$enclosure['length'] : 0; + $medium = is_string($enclosure['medium'] ?? null) ? $enclosure['medium'] : ''; + $mime = is_string($enclosure['type'] ?? null) ? $enclosure['type'] : ''; $thumbnails = $enclosure['thumbnails'] ?? null; if (!is_array($thumbnails)) { $thumbnails = []; } - $etitle = $enclosure['title'] ?? ''; + $etitle = is_string($enclosure['title'] ?? null) ? $enclosure['title'] : ''; $content .= "\n"; $content .= '
'; @@ -249,16 +251,16 @@ HTML; } } - if (self::enclosureIsImage($enclosure)) { + if (self::enclosureIsImage(['url' => $elink, 'length' => $length, 'medium' => $medium, 'type' => $mime])) { $content .= '

'; } elseif ($medium === 'audio' || str_starts_with($mime, 'audio')) { $content .= '

💾

'; } elseif ($medium === 'video' || str_starts_with($mime, 'video')) { $content .= '

💾

'; } else { //e.g. application, text, unknown @@ -273,7 +275,9 @@ HTML; $credits = [$credits]; } foreach ($credits as $credit) { - $content .= '

© ' . $credit . '

'; + if (is_string($credit)) { + $content .= '

© ' . $credit . '

'; + } } } if ($description != '') { -- cgit v1.2.3