From b3121709d62d9fadf890e523b9c9dba7cf702d25 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 14 Apr 2023 14:23:45 +0200 Subject: PHPStan Level 6 FreshRSS_Search FreshRSS_Entry (#5292) * PHPStan Level 6 FreshRSS_Search FreshRSS_Entry * Minor fix * Type fix * Apply suggestions from code review Co-authored-by: Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> * Minor types syntax Compatibility Intelephense --------- Co-authored-by: Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> --- lib/Minz/Helper.php | 7 ++++++- lib/Minz/Request.php | 9 +++++---- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'lib/Minz') diff --git a/lib/Minz/Helper.php b/lib/Minz/Helper.php index 92e97ad6c..8ecc1af8d 100644 --- a/lib/Minz/Helper.php +++ b/lib/Minz/Helper.php @@ -12,8 +12,13 @@ class Minz_Helper { /** * Wrapper for htmlspecialchars. * Force UTf-8 value and can be used on array too. + * + * @phpstan-template T of string|array + * @phpstan-param T $var + * @phpstan-return T + * * @param string|array $var - * @return ($var is array ? array : string) + * @return string|array */ public static function htmlspecialchars_utf8($var) { if (is_array($var)) { diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php index a03aff18b..7957610e2 100644 --- a/lib/Minz/Request.php +++ b/lib/Minz/Request.php @@ -49,8 +49,10 @@ class Minz_Request { $p = self::$params[$key]; if (is_object($p) || $specialchars) { return $p; - } else { + } elseif (is_string($p) || is_array($p)) { return Minz_Helper::htmlspecialchars_utf8($p); + } else { + return $p; } } else { return $default; @@ -66,8 +68,7 @@ class Minz_Request { return $specialchars ? Minz_Helper::htmlspecialchars_utf8(self::$params[$key]) : self::$params[$key]; } - /** @return bool|null */ - public static function paramTernary(string $key) { + public static function paramTernary(string $key): ?bool { if (isset(self::$params[$key])) { $p = self::$params[$key]; $tp = is_string($p) ? trim($p) : true; @@ -457,7 +458,7 @@ class Minz_Request { /** * @return array */ - public static function getPreferredLanguages() { + public static function getPreferredLanguages(): array { if (preg_match_all('/(^|,)\s*(?P[^;,]+)/', $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '', $matches)) { return $matches['lang']; } -- cgit v1.2.3