From 67c42b0e7c4250d7befe61e35994d8f6e439ca7a Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 15 Jun 2025 01:17:20 +0200 Subject: Remove several PHPStan ignore (#7665) * Remove several PHPStan ignore * One syntax error * PDO returns int, not bool (MySQL and SQLite Boolean types are aliases for tinyint). * A few missing type hints * Revert strange PHPStan bug --- app/Models/CategoryDAO.php | 22 +++++++++++----------- app/Models/FeedDAO.php | 30 ++++++++++++++++++++++-------- app/Models/TagDAO.php | 6 +++--- 3 files changed, 36 insertions(+), 22 deletions(-) (limited to 'app') diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php index 7dfb32076..3a714afed 100644 --- a/app/Models/CategoryDAO.php +++ b/app/Models/CategoryDAO.php @@ -244,16 +244,16 @@ SQL; public function searchById(int $id): ?FreshRSS_Category { $sql = 'SELECT * FROM `_category` WHERE id=:id'; $res = $this->fetchAssoc($sql, ['id' => $id]) ?? []; - /** @var array $res */ - $categories = self::daoToCategories($res); // @phpstan-ignore varTag.type + /** @var list $res */ + $categories = self::daoToCategories($res); return reset($categories) ?: null; } public function searchByName(string $name): ?FreshRSS_Category { $sql = 'SELECT * FROM `_category` WHERE name=:name'; $res = $this->fetchAssoc($sql, ['name' => $name]) ?? []; - /** @var array $res */ - $categories = self::daoToCategories($res); // @phpstan-ignore varTag.type + /** @var list $res */ + $categories = self::daoToCategories($res); return reset($categories) ?: null; } @@ -290,8 +290,8 @@ SQL; $stm = $this->pdo->prepare($sql); $values = [ ':priority' => FreshRSS_Feed::PRIORITY_CATEGORY ]; if ($stm !== false && $stm->execute($values) && ($res = $stm->fetchAll(PDO::FETCH_ASSOC)) !== false) { - /** @var list $res */ + /** @var list $res */ return self::daoToCategoriesPrepopulated($res); } else { $info = $stm === false ? $this->pdo->errorInfo() : $stm->errorInfo(); @@ -304,8 +304,8 @@ SQL; } } else { $res = $this->fetchAssoc('SELECT * FROM `_category` ORDER BY name') ?? []; - /** @var list $res */ - return empty($res) ? [] : self::daoToCategories($res); // @phpstan-ignore varTag.type + /** @var list $res */ + return empty($res) ? [] : self::daoToCategories($res); } } @@ -319,7 +319,7 @@ SQL; $stm->bindValue(':lu', time() - $defaultCacheDuration, PDO::PARAM_INT) && $stm->execute()) { $res = $stm->fetchAll(PDO::FETCH_ASSOC); - /** @var list $res */ + /** @var list $res */ return self::daoToCategories($res); } else { $info = $stm !== false ? $stm->errorInfo() : $this->pdo->errorInfo(); @@ -335,8 +335,8 @@ SQL; public function getDefault(): ?FreshRSS_Category { $sql = 'SELECT * FROM `_category` WHERE id=:id'; $res = $this->fetchAssoc($sql, [':id' => self::DEFAULTCATEGORYID]) ?? []; - /** @var array $res */ - $categories = self::daoToCategories($res); // @phpstan-ignore varTag.type + /** @var list $res */ + $categories = self::daoToCategories($res); if (isset($categories[self::DEFAULTCATEGORYID])) { return $categories[self::DEFAULTCATEGORYID]; } else { diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index 464d3fe06..e6e5d2940 100644 --- a/app/Models/FeedDAO.php +++ b/app/Models/FeedDAO.php @@ -307,7 +307,7 @@ SQL; if ($stm !== false) { while (is_array($row = $stm->fetch(PDO::FETCH_ASSOC))) { /** @var array{id:int,url:string,kind:int,category:int,name:string,website:string,description:string,lastUpdate:int,priority?:int, - * pathEntries?:string,httpAuth:string,error:int|bool,ttl?:int,attributes?:string} $row */ + * pathEntries?:string,httpAuth:string,error:int,ttl?:int,attributes?:string} $row */ yield $row; } } else { @@ -327,14 +327,21 @@ SQL; if (!is_array($res)) { return null; } - $feeds = self::daoToFeeds($res); // @phpstan-ignore argument.type + /** @var list $res */ + $feeds = self::daoToFeeds($res); return $feeds[$id] ?? null; } public function searchByUrl(string $url): ?FreshRSS_Feed { $sql = 'SELECT * FROM `_feed` WHERE url=:url'; $res = $this->fetchAssoc($sql, [':url' => $url]); - return empty($res[0]) ? null : (current(self::daoToFeeds($res)) ?: null); // @phpstan-ignore argument.type + if (!is_array($res)) { + return null; + } + /** @var list $res */ + return empty($res[0]) ? null : (current(self::daoToFeeds($res)) ?: null); } /** @return list */ @@ -349,7 +356,12 @@ SQL; public function listFeeds(): array { $sql = 'SELECT * FROM `_feed` ORDER BY name'; $res = $this->fetchAssoc($sql); - return $res == null ? [] : self::daoToFeeds($res); // @phpstan-ignore argument.type + if (!is_array($res)) { + return []; + } + /** @var list $res */ + return self::daoToFeeds($res); } /** @return array */ @@ -361,8 +373,8 @@ SQL; $sql .= 'WHERE id_feed=' . intval($id_feed); } $res = $this->fetchAssoc($sql); - /** @var list|null $res */ - if ($res == null) { + /** @var list|null $res */ + if ($res === null) { return []; } $newestItemUsec = []; @@ -386,7 +398,7 @@ SQL; $stm = $this->pdo->query($sql); if ($stm !== false && ($res = $stm->fetchAll(PDO::FETCH_ASSOC)) !== false) { /** @var list $res */ + * pathEntries?:string,httpAuth?:string,error?:int,ttl?:int,attributes?:string,cache_nbUnreads?:int,cache_nbEntries?:int}> $res */ return self::daoToFeeds($res); } else { $info = $this->pdo->errorInfo(); @@ -425,7 +437,9 @@ SQL; if (!is_array($res)) { return []; } - $feeds = self::daoToFeeds($res); // @phpstan-ignore argument.type + /** @var list $res */ + $feeds = self::daoToFeeds($res); uasort($feeds, static fn(FreshRSS_Feed $a, FreshRSS_Feed $b) => strnatcasecmp($a->name(), $b->name())); return $feeds; } diff --git a/app/Models/TagDAO.php b/app/Models/TagDAO.php index a253f37c1..05b01f94a 100644 --- a/app/Models/TagDAO.php +++ b/app/Models/TagDAO.php @@ -140,8 +140,8 @@ SQL; return; } while (is_array($row = $stm->fetch(PDO::FETCH_ASSOC))) { - /** @var array{id_tag:int,id_entry:int|numeric-string}> $row */ - yield $row; // @phpstan-ignore generator.valueType + /** @var array{id_tag:int,id_entry:int|numeric-string} $row */ + yield $row; } } @@ -336,7 +336,7 @@ SQL; if ($stm !== false && $stm->execute($values) && ($lines = $stm->fetchAll(PDO::FETCH_ASSOC)) !== false) { $result = []; foreach ($lines as $line) { - /** @var array{id:int,name:string,checked:bool|int} $line */ + /** @var array{id:int,name:string,checked:int} $line */ $result[] = [ 'id' => (int)($line['id']), 'name' => $line['name'], -- cgit v1.2.3