From bd9fa803f1f0c23face77fa1bc550d1198ce5ad6 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 2 May 2023 14:38:32 +0200 Subject: PHPStan Level 7 complete DAOs (#5354) * PHPStan Level 7 complete DAOs * Finalise PHPStan Level 7 for CategoryDAO * PHPStan Level 7 for Context and Search * Apply suggestions from code review Co-authored-by: Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> --- app/Models/Context.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'app/Models/Context.php') diff --git a/app/Models/Context.php b/app/Models/Context.php index 03006cbbf..ce29ebd5c 100644 --- a/app/Models/Context.php +++ b/app/Models/Context.php @@ -16,11 +16,11 @@ final class FreshRSS_Context { */ public static $system_conf; /** - * @var array + * @var array */ public static $categories = array(); /** - * @var array + * @var array */ public static $tags = array(); /** @@ -67,6 +67,7 @@ final class FreshRSS_Context { */ public static $state = 0; /** + * @phpstan-var 'ASC'|'DESC' * @var string */ public static $order = 'DESC'; @@ -217,7 +218,8 @@ final class FreshRSS_Context { } self::$search = new FreshRSS_BooleanSearch(Minz_Request::paramString('search')); - self::$order = Minz_Request::paramString('order') ?: self::$user_conf->sort_order; + $order = Minz_Request::paramString('order') ?: self::$user_conf->sort_order; + self::$order = in_array($order, ['ASC', 'DESC'], true) ? $order : 'DESC'; self::$number = Minz_Request::paramInt('nb') ?: self::$user_conf->posts_per_page; if (self::$number > self::$user_conf->max_posts_per_rss) { self::$number = max( @@ -381,7 +383,7 @@ final class FreshRSS_Context { if ($feed === null) { $feedDAO = FreshRSS_Factory::createFeedDao(); $feed = $feedDAO->searchById($id); - if (!$feed) { + if ($feed === null) { throw new FreshRSS_Context_Exception('Invalid feed: ' . $id); } } @@ -397,9 +399,10 @@ final class FreshRSS_Context { if (!isset(self::$categories[$id])) { $catDAO = FreshRSS_Factory::createCategoryDao(); $cat = $catDAO->searchById($id); - if (!$cat) { + if ($cat === null) { throw new FreshRSS_Context_Exception('Invalid category: ' . $id); } + //self::$categories[$id] = $cat; } else { $cat = self::$categories[$id]; } @@ -412,9 +415,10 @@ final class FreshRSS_Context { if (!isset(self::$tags[$id])) { $tagDAO = FreshRSS_Factory::createTagDao(); $tag = $tagDAO->searchById($id); - if (!$tag) { + if ($tag === null) { throw new FreshRSS_Context_Exception('Invalid tag: ' . $id); } + //self::$tags[$id] = $tag; } else { $tag = self::$tags[$id]; } @@ -541,6 +545,6 @@ final class FreshRSS_Context { public static function defaultTimeZone(): string { $timezone = ini_get('date.timezone'); - return $timezone != '' ? $timezone : 'UTC'; + return $timezone != false ? $timezone : 'UTC'; } } -- cgit v1.2.3