From a80a5f48a16e7d232168a7aaa68e9a1804235ce1 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 18 Dec 2023 17:59:16 +0100 Subject: Pass PHPStan level 8 (#5946) * Pass PHPStan level 8 And prepare for PHPStan level 9 https://phpstan.org/user-guide/rule-levels * Revert wrong replace in comment * Fix PHPStan level 8 * Update PHPStan and other dev dependencies * Remove obsolete comment * noVariableVariables and towards bleedingEdge https://github.com/phpstan/phpstan-strict-rules https://phpstan.org/blog/what-is-bleeding-edge * More bleedingEdge * A bit more PHPStan level 9 * More PHPStan level 9 * Prepare for booleansInConditions Ignore int and null * Revert wrong line * More fixes * Fix keep_max_n_unread * Stricter attribute functions * Stricter callHooks and more PHPStan level 9 * More typing * A tiny more --- app/Models/CategoryDAO.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'app/Models/CategoryDAO.php') diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php index 20347e4f2..417ff7a6c 100644 --- a/app/Models/CategoryDAO.php +++ b/app/Models/CategoryDAO.php @@ -30,8 +30,8 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo { } elseif ('attributes' === $name) { //v1.15.0 $ok = $this->pdo->exec('ALTER TABLE `_category` ADD COLUMN attributes TEXT') !== false; - /** @var array $feeds */ + /** @var array $feeds */ $feeds = $this->fetchAssoc('SELECT * FROM `_feed`') ?? []; $stm = $this->pdo->prepare('UPDATE `_feed` SET attributes = :attributes WHERE id = :id'); @@ -153,7 +153,7 @@ SQL; } /** - * @param array{'name':string,'kind':int,'attributes'?:string|array} $valuesTmp + * @param array{'name':string,'kind':int,'attributes'?:array|mixed|null} $valuesTmp * @return int|false * @throws JsonException */ @@ -230,6 +230,7 @@ SQL; $stm = $this->pdo->query($sql); if ($stm !== false) { while ($row = $stm->fetch(PDO::FETCH_ASSOC)) { + /** @var array{'id':int,'name':string,'kind':int,'lastUpdate':int,'error':int,'attributes'?:array} $row */ yield $row; } } else { @@ -245,7 +246,7 @@ SQL; public function searchById(int $id): ?FreshRSS_Category { $sql = 'SELECT * FROM `_category` WHERE id=:id'; $res = $this->fetchAssoc($sql, ['id' => $id]) ?? []; - /** @var array $res */ + /** @var array $res */ $cat = self::daoToCategory($res); return $cat[0] ?? null; } @@ -253,7 +254,7 @@ SQL; public function searchByName(string $name): ?FreshRSS_Category { $sql = 'SELECT * FROM `_category` WHERE name=:name'; $res = $this->fetchAssoc($sql, ['name' => $name]) ?? []; - /** @var array $res */ + /** @var array $res */ $cat = self::daoToCategory($res); return $cat[0] ?? null; } @@ -263,8 +264,8 @@ SQL; $categories = $this->listCategories($prePopulateFeeds, $details); uasort($categories, static function (FreshRSS_Category $a, FreshRSS_Category $b) { - $aPosition = $a->attributes('position'); - $bPosition = $b->attributes('position'); + $aPosition = $a->attributeInt('position'); + $bPosition = $b->attributeInt('position'); if ($aPosition === $bPosition) { return ($a->name() < $b->name()) ? -1 : 1; } elseif (null === $aPosition) { @@ -332,9 +333,9 @@ SQL; public function getDefault(): ?FreshRSS_Category { $sql = 'SELECT * FROM `_category` WHERE id=:id'; - $res = $this->fetchAssoc($sql, [':id' => self::DEFAULTCATEGORYID]); + $res = $this->fetchAssoc($sql, [':id' => self::DEFAULTCATEGORYID]) ?? []; /** @var array $res */ - $cat = self::daoToCategory($res ?? []); + $cat = self::daoToCategory($res); if (isset($cat[0])) { return $cat[0]; } else { @@ -444,7 +445,7 @@ SQL; $feedDao::daoToFeed($feedsDao, $previousLine['c_id']) ); $cat->_kind($previousLine['c_kind']); - $cat->_attributes('', $previousLine['c_attributes'] ?? '[]'); + $cat->_attributes($previousLine['c_attributes'] ?? '[]'); $list[(int)$previousLine['c_id']] = $cat; $feedsDao = []; //Prepare for next category @@ -464,7 +465,7 @@ SQL; $cat->_kind($previousLine['c_kind']); $cat->_lastUpdate($previousLine['c_last_update'] ?? 0); $cat->_error($previousLine['c_error'] ?? 0); - $cat->_attributes('', $previousLine['c_attributes'] ?? []); + $cat->_attributes($previousLine['c_attributes'] ?? []); $list[(int)$previousLine['c_id']] = $cat; } @@ -487,7 +488,7 @@ SQL; $cat->_kind($dao['kind']); $cat->_lastUpdate($dao['lastUpdate'] ?? 0); $cat->_error($dao['error'] ?? 0); - $cat->_attributes('', $dao['attributes'] ?? ''); + $cat->_attributes($dao['attributes'] ?? ''); $list[] = $cat; } -- cgit v1.2.3