diff options
| author | 2023-05-02 14:38:32 +0200 | |
|---|---|---|
| committer | 2023-05-02 14:38:32 +0200 | |
| commit | bd9fa803f1f0c23face77fa1bc550d1198ce5ad6 (patch) | |
| tree | edba662e84e70a6b0f23c8379d4ef174f714e999 /app/Models/Context.php | |
| parent | 4de1d5efea128e6cc70c71bad9be28d01e851f81 (diff) | |
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>
Diffstat (limited to 'app/Models/Context.php')
| -rw-r--r-- | app/Models/Context.php | 18 |
1 files changed, 11 insertions, 7 deletions
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<FreshRSS_Category> + * @var array<int,FreshRSS_Category> */ public static $categories = array(); /** - * @var array<string> + * @var array<int,FreshRSS_Tag> */ 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'; } } |
