From b1d24fbdb7d1cc948c946295035dad6df550fb7e Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 27 Dec 2024 12:12:49 +0100 Subject: PHPStan 2.0 (#7131) * PHPStan 2.0 fix https://github.com/FreshRSS/FreshRSS/issues/6989 https://github.com/phpstan/phpstan/releases/tag/2.0.0 https://github.com/phpstan/phpstan/blob/2.0.x/UPGRADING.md * More * More * Done * fix i18n CLI * Restore a PHPStan Next test For work towards PHPStan Level 10 * 4 more on Level 10 * fix getTagsForEntry * API at Level 10 * More Level 10 * Finish Minz at Level 10 * Finish CLI at Level 10 * Finish Controllers at Level 10 * More Level 10 * More * Pass bleedingEdge * Clean PHPStan options and add TODOs * Level 10 for main config * More * Consitency array vs. list * Sanitize themes get_infos * Simplify TagDAO->getTagsForEntries() * Finish reportAnyTypeWideningInVarTag * Prepare checkBenevolentUnionTypes and checkImplicitMixed * Fixes * Refix * Another fix * Casing of __METHOD__ constant --- app/Models/Context.php | 49 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) (limited to 'app/Models/Context.php') diff --git a/app/Models/Context.php b/app/Models/Context.php index 6cdda909c..b9cc77498 100644 --- a/app/Models/Context.php +++ b/app/Models/Context.php @@ -8,11 +8,11 @@ declare(strict_types=1); final class FreshRSS_Context { /** - * @var array + * @var list */ private static array $categories = []; /** - * @var array + * @var list */ private static array $tags = []; public static string $name = ''; @@ -176,7 +176,7 @@ final class FreshRSS_Context { FreshRSS_Context::$user_conf = null; } - /** @return array */ + /** @return list */ public static function categories(): array { if (empty(self::$categories)) { $catDAO = FreshRSS_Factory::createCategoryDao(); @@ -185,12 +185,12 @@ final class FreshRSS_Context { return self::$categories; } - /** @return array */ + /** @return list */ public static function feeds(): array { return FreshRSS_Category::findFeeds(self::categories()); } - /** @return array */ + /** @return list */ public static function labels(bool $precounts = false): array { if (empty(self::$tags) || $precounts) { $tagDAO = FreshRSS_Factory::createTagDao(); @@ -429,7 +429,6 @@ final class FreshRSS_Context { self::$name = _t('index.feed.title_fav'); self::$description = FreshRSS_Context::systemConf()->meta_description; self::$get_unread = self::$total_starred['unread']; - // Update state if favorite is not yet enabled. self::$state = self::$state | FreshRSS_Entry::STATE_FAVORITE; break; @@ -437,11 +436,7 @@ final class FreshRSS_Context { // We try to find the corresponding feed. When allowing robots, always retrieve the full feed including description $feed = FreshRSS_Context::systemConf()->allow_robots ? null : FreshRSS_Category::findFeed(self::$categories, $id); if ($feed === null) { - $feedDAO = FreshRSS_Factory::createFeedDao(); - $feed = $feedDAO->searchById($id); - if ($feed === null) { - throw new FreshRSS_Context_Exception('Invalid feed: ' . $id); - } + throw new FreshRSS_Context_Exception('Invalid feed: ' . $id); } self::$current_get['feed'] = $id; self::$current_get['category'] = $feed->categoryId(); @@ -452,15 +447,15 @@ final class FreshRSS_Context { case 'c': // We try to find the corresponding category. self::$current_get['category'] = $id; - if (!isset(self::$categories[$id])) { - $catDAO = FreshRSS_Factory::createCategoryDao(); - $cat = $catDAO->searchById($id); - if ($cat === null) { - throw new FreshRSS_Context_Exception('Invalid category: ' . $id); + $cat = null; + foreach (self::$categories as $category) { + if ($category->id() === $id) { + $cat = $category; + break; } - self::$categories[$id] = $cat; - } else { - $cat = self::$categories[$id]; + } + if ($cat === null) { + throw new FreshRSS_Context_Exception('Invalid category: ' . $id); } self::$name = $cat->name(); self::$get_unread = $cat->nbNotRead(); @@ -468,15 +463,15 @@ final class FreshRSS_Context { case 't': // We try to find the corresponding tag. self::$current_get['tag'] = $id; - if (!isset(self::$tags[$id])) { - $tagDAO = FreshRSS_Factory::createTagDao(); - $tag = $tagDAO->searchById($id); - if ($tag === null) { - throw new FreshRSS_Context_Exception('Invalid tag: ' . $id); + $tag = null; + foreach (self::$tags as $t) { + if ($t->id() === $id) { + $tag = $t; + break; } - self::$tags[$id] = $tag; - } else { - $tag = self::$tags[$id]; + } + if ($tag === null) { + throw new FreshRSS_Context_Exception('Invalid tag: ' . $id); } self::$name = $tag->name(); self::$get_unread = $tag->nbUnread(); -- cgit v1.2.3