From f3760f138dcbaf7a2190336a0378cf1b2190c9f5 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 17 Apr 2023 08:30:21 +0200 Subject: Complete PHPStan Level 6 (#5305) * Complete PHPStan Level 6 Fix https://github.com/FreshRSS/FreshRSS/issues/4112 And initiate PHPStan Level 7 * PHPStan Level 6 for tests * Use phpstan/phpstan-phpunit * Update to PHPStan version 1.10 * Fix mixed bug * Fix mixed return bug * Fix paginator bug * Fix FreshRSS_UserConfiguration * A couple more Minz_Configuration bug fixes * A few trivial PHPStan Level 7 fixes * A few more simple PHPStan Level 7 * More files passing PHPStan Level 7 Add interface to replace removed class from https://github.com/FreshRSS/FreshRSS/pull/5251 * A few more PHPStan Level 7 preparations * A few last details --- app/Models/EntryDAOSQLite.php | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'app/Models/EntryDAOSQLite.php') diff --git a/app/Models/EntryDAOSQLite.php b/app/Models/EntryDAOSQLite.php index e509097f2..c86791372 100644 --- a/app/Models/EntryDAOSQLite.php +++ b/app/Models/EntryDAOSQLite.php @@ -25,7 +25,7 @@ class FreshRSS_EntryDAOSQLite extends FreshRSS_EntryDAO { /** @param array $errorInfo */ protected function autoUpdateDb(array $errorInfo): bool { if ($tableInfo = $this->pdo->query("PRAGMA table_info('entry')")) { - $columns = $tableInfo->fetchAll(PDO::FETCH_COLUMN, 1); + $columns = $tableInfo->fetchAll(PDO::FETCH_COLUMN, 1) ?: []; foreach (['attributes'] as $column) { if (!in_array($column, $columns)) { return $this->addColumn($column); @@ -34,14 +34,14 @@ class FreshRSS_EntryDAOSQLite extends FreshRSS_EntryDAO { } if ($tableInfo = $this->pdo->query("SELECT sql FROM sqlite_master where name='tag'")) { $showCreate = $tableInfo->fetchColumn(); - if (stripos($showCreate, 'tag') === false) { + if (is_string($showCreate) && stripos($showCreate, 'tag') === false) { $tagDAO = FreshRSS_Factory::createTagDao(); return $tagDAO->createTagTable(); //v1.12.0 } } if ($tableInfo = $this->pdo->query("SELECT sql FROM sqlite_master where name='entrytmp'")) { $showCreate = $tableInfo->fetchColumn(); - if (stripos($showCreate, 'entrytmp') === false) { + if (is_string($showCreate) && stripos($showCreate, 'entrytmp') === false) { return $this->createEntryTempTable(); //v1.7.0 } } @@ -78,20 +78,20 @@ DROP TABLE IF EXISTS `tmp`; return $result; } - protected function updateCacheUnreads($catId = false, $feedId = false) { + protected function updateCacheUnreads(?int $catId = null, ?int $feedId = null): bool { $sql = 'UPDATE `_feed` ' . 'SET `cache_nbUnreads`=(' . 'SELECT COUNT(*) AS nbUnreads FROM `_entry` e ' . 'WHERE e.id_feed=`_feed`.id AND e.is_read=0)'; $hasWhere = false; $values = array(); - if ($feedId !== false) { + if ($feedId != null) { $sql .= ' WHERE'; $hasWhere = true; $sql .= ' id=?'; $values[] = $feedId; } - if ($catId !== false) { + if ($catId != null) { $sql .= $hasWhere ? ' AND' : ' WHERE'; $hasWhere = true; $sql .= ' category=?'; @@ -117,8 +117,8 @@ DROP TABLE IF EXISTS `tmp`; * same if it is an array or not. * * @param string|array $ids - * @param boolean $is_read - * @return integer|false affected rows + * @param bool $is_read + * @return int|false affected rows */ public function markRead($ids, bool $is_read = true) { FreshRSS_UserDAO::touch(); @@ -176,9 +176,9 @@ DROP TABLE IF EXISTS `tmp`; * separated. * * @param string $idMax fail safe article ID - * @param boolean $onlyFavorites - * @param integer $priorityMin - * @return integer|false affected rows + * @param bool $onlyFavorites + * @param int $priorityMin + * @return int|false affected rows */ public function markReadEntries(string $idMax = '0', bool $onlyFavorites = false, int $priorityMin = 0, ?FreshRSS_BooleanSearch $filters = null, int $state = 0, bool $is_read = true) { @@ -205,7 +205,7 @@ DROP TABLE IF EXISTS `tmp`; return false; } $affected = $stm->rowCount(); - if (($affected > 0) && (!$this->updateCacheUnreads(false, false))) { + if (($affected > 0) && (!$this->updateCacheUnreads(null, null))) { return false; } return $affected; @@ -218,9 +218,9 @@ DROP TABLE IF EXISTS `tmp`; * * If $idMax equals 0, a deprecated debug message is logged * - * @param integer $id category ID + * @param int $id category ID * @param string $idMax fail safe article ID - * @return integer|false affected rows + * @return int|false affected rows */ public function markReadCat(int $id, string $idMax = '0', ?FreshRSS_BooleanSearch $filters = null, int $state = 0, bool $is_read = true) { FreshRSS_UserDAO::touch(); @@ -244,7 +244,7 @@ DROP TABLE IF EXISTS `tmp`; return false; } $affected = $stm->rowCount(); - if (($affected > 0) && (!$this->updateCacheUnreads($id, false))) { + if (($affected > 0) && (!$this->updateCacheUnreads($id, null))) { return false; } return $affected; @@ -252,9 +252,9 @@ DROP TABLE IF EXISTS `tmp`; /** * Mark all the articles in a tag as read. - * @param integer $id tag ID, or empty for targeting any tag + * @param int $id tag ID, or empty for targeting any tag * @param string $idMax max article ID - * @return integer|false affected rows + * @return int|false affected rows */ public function markReadTag($id = 0, string $idMax = '0', ?FreshRSS_BooleanSearch $filters = null, int $state = 0, bool $is_read = true) { FreshRSS_UserDAO::touch(); @@ -283,7 +283,7 @@ DROP TABLE IF EXISTS `tmp`; return false; } $affected = $stm->rowCount(); - if (($affected > 0) && (!$this->updateCacheUnreads(false, false))) { + if (($affected > 0) && (!$this->updateCacheUnreads(null, null))) { return false; } return $affected; -- cgit v1.2.3