diff options
| author | 2023-03-31 08:23:39 +0200 | |
|---|---|---|
| committer | 2023-03-31 08:23:39 +0200 | |
| commit | 288ed04ccc30b58373576dc3be811aee43e67034 (patch) | |
| tree | 27f4c571e04d64c97737416dfa2b8d65f481dfd8 /app/Models | |
| parent | c9d5fe2da12cbc3a071ebf9a518afe2789bb3d61 (diff) | |
PHPStan level 6 for all PDO and Exception classes (#5239)
* PHPStan level 6 for all PDO and Exception classes
Contributes to https://github.com/FreshRSS/FreshRSS/issues/4112
* Fix type
* Now also our remaining own librairies
* Motivation for a few more files
* A few more DAO classes
* Last interface
Diffstat (limited to 'app/Models')
| -rw-r--r-- | app/Models/BooleanSearch.php | 11 | ||||
| -rw-r--r-- | app/Models/CategoryDAO.php | 3 | ||||
| -rw-r--r-- | app/Models/CategoryDAOSQLite.php | 3 | ||||
| -rw-r--r-- | app/Models/DatabaseDAO.php | 18 | ||||
| -rw-r--r-- | app/Models/DatabaseDAOPGSQL.php | 5 | ||||
| -rw-r--r-- | app/Models/DatabaseDAOSQLite.php | 5 | ||||
| -rw-r--r-- | app/Models/FeedDAO.php | 3 | ||||
| -rw-r--r-- | app/Models/FeedDAOSQLite.php | 3 | ||||
| -rw-r--r-- | app/Models/ReadingMode.php | 55 | ||||
| -rw-r--r-- | app/Models/TagDAO.php | 3 | ||||
| -rw-r--r-- | app/Models/TagDAOSQLite.php | 3 | ||||
| -rw-r--r-- | app/Models/UserDAO.php | 13 |
12 files changed, 62 insertions, 63 deletions
diff --git a/app/Models/BooleanSearch.php b/app/Models/BooleanSearch.php index 279040a5a..f2e16f972 100644 --- a/app/Models/BooleanSearch.php +++ b/app/Models/BooleanSearch.php @@ -10,10 +10,11 @@ class FreshRSS_BooleanSearch { /** @var array<FreshRSS_BooleanSearch|FreshRSS_Search> */ private $searches = array(); - /** @var string 'AND' or 'OR' or 'AND NOT' */ + /** @var 'AND'|'OR'|'AND NOT' */ private $operator; - public function __construct(string $input, int $level = 0, $operator = 'AND') { + /** @param 'AND'|'OR'|'AND NOT' $operator */ + public function __construct(string $input, int $level = 0, string $operator = 'AND') { $this->operator = $operator; $input = trim($input); if ($input == '') { @@ -221,7 +222,7 @@ class FreshRSS_BooleanSearch { return false; } - private function parseOrSegments(string $input) { + private function parseOrSegments(string $input): void { $input = trim($input); if ($input == '') { return; @@ -258,13 +259,13 @@ class FreshRSS_BooleanSearch { return $this->searches; } - /** @return string 'AND' or 'OR' depending on how this BooleanSearch should be combined */ + /** @return 'AND'|'OR'|'AND NOT' depending on how this BooleanSearch should be combined */ public function operator(): string { return $this->operator; } /** @param FreshRSS_BooleanSearch|FreshRSS_Search $search */ - public function add($search) { + public function add($search): void { $this->searches[] = $search; } diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php index 02845ebe7..dd97bd6cc 100644 --- a/app/Models/CategoryDAO.php +++ b/app/Models/CategoryDAO.php @@ -75,7 +75,8 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo { return false; } - protected function autoUpdateDb(array $errorInfo) { + /** @param array<string> $errorInfo */ + protected function autoUpdateDb(array $errorInfo): bool { if (isset($errorInfo[0])) { if ($errorInfo[0] === FreshRSS_DatabaseDAO::ER_BAD_FIELD_ERROR || $errorInfo[0] === FreshRSS_DatabaseDAOPGSQL::UNDEFINED_COLUMN) { $errorLines = explode("\n", $errorInfo[2], 2); // The relevant column name is on the first line, other lines are noise diff --git a/app/Models/CategoryDAOSQLite.php b/app/Models/CategoryDAOSQLite.php index 363ffb427..870106f20 100644 --- a/app/Models/CategoryDAOSQLite.php +++ b/app/Models/CategoryDAOSQLite.php @@ -2,7 +2,8 @@ class FreshRSS_CategoryDAOSQLite extends FreshRSS_CategoryDAO { - protected function autoUpdateDb(array $errorInfo) { + /** @param array<string> $errorInfo */ + protected function autoUpdateDb(array $errorInfo): bool { if ($tableInfo = $this->pdo->query("PRAGMA table_info('category')")) { $columns = $tableInfo->fetchAll(PDO::FETCH_COLUMN, 1); foreach (['kind', 'lastUpdate', 'error', 'attributes'] as $column) { diff --git a/app/Models/DatabaseDAO.php b/app/Models/DatabaseDAO.php index bf9cbb2d3..28dd36cd9 100644 --- a/app/Models/DatabaseDAO.php +++ b/app/Models/DatabaseDAO.php @@ -63,13 +63,15 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo { return count(array_keys($tables, true, true)) == count($tables); } + /** @return array<array<string,string|bool>> */ public function getSchema(string $table): array { $sql = 'DESC `_' . $table . '`'; $stm = $this->pdo->query($sql); return $this->listDaoToSchema($stm->fetchAll(PDO::FETCH_ASSOC)); } - public function checkTable(string $table, $schema): bool { + /** @param array<string> $schema */ + public function checkTable(string $table, array $schema): bool { $columns = $this->getSchema($table); $ok = (count($columns) == count($schema)); @@ -120,6 +122,10 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo { )); } + /** + * @param array<string,string> $dao + * @return array<string,string|bool> + */ public function daoToSchema(array $dao): array { return array( 'name' => $dao['Field'], @@ -129,7 +135,11 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo { ); } - public function listDaoToSchema($listDAO): array { + /** + * @param array<array<string,string>> $listDAO + * @return array<array<string,string|bool>> + */ + public function listDaoToSchema(array $listDAO): array { $list = array(); foreach ($listDAO as $dao) { @@ -185,14 +195,14 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo { return $ok; } - public function minorDbMaintenance() { + public function minorDbMaintenance(): void { $catDAO = FreshRSS_Factory::createCategoryDao(); $catDAO->resetDefaultCategoryName(); $this->ensureCaseInsensitiveGuids(); } - private static function stdError($error): bool { + private static function stdError(string $error): bool { if (defined('STDERR')) { fwrite(STDERR, $error . "\n"); } diff --git a/app/Models/DatabaseDAOPGSQL.php b/app/Models/DatabaseDAOPGSQL.php index 6ff706250..b1db0f347 100644 --- a/app/Models/DatabaseDAOPGSQL.php +++ b/app/Models/DatabaseDAOPGSQL.php @@ -33,6 +33,7 @@ class FreshRSS_DatabaseDAOPGSQL extends FreshRSS_DatabaseDAOSQLite { return count(array_keys($tables, true, true)) == count($tables); } + /** @return array<array<string,string|bool>> */ public function getSchema(string $table): array { $sql = 'select column_name as field, data_type as type, column_default as default, is_nullable as null from INFORMATION_SCHEMA.COLUMNS where table_name = ?'; $stm = $this->pdo->prepare($sql); @@ -40,6 +41,10 @@ class FreshRSS_DatabaseDAOPGSQL extends FreshRSS_DatabaseDAOSQLite { return $this->listDaoToSchema($stm->fetchAll(PDO::FETCH_ASSOC)); } + /** + * @param array<string,string> $dao + * @return array<string,string|bool> + */ public function daoToSchema(array $dao): array { return array( 'name' => $dao['field'], diff --git a/app/Models/DatabaseDAOSQLite.php b/app/Models/DatabaseDAOSQLite.php index e5a6f5a04..3fab1134d 100644 --- a/app/Models/DatabaseDAOSQLite.php +++ b/app/Models/DatabaseDAOSQLite.php @@ -25,6 +25,7 @@ class FreshRSS_DatabaseDAOSQLite extends FreshRSS_DatabaseDAO { return count(array_keys($tables, true, true)) == count($tables); } + /** @return array<array<string,string|bool>> */ public function getSchema(string $table): array { $sql = 'PRAGMA table_info(' . $table . ')'; $stm = $this->pdo->query($sql); @@ -45,6 +46,10 @@ class FreshRSS_DatabaseDAOSQLite extends FreshRSS_DatabaseDAO { )); } + /** + * @param array<string,string> $dao + * @return array<string,string|bool> + */ public function daoToSchema(array $dao): array { return [ 'name' => $dao['name'], diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index 1047a218b..2a123e0db 100644 --- a/app/Models/FeedDAO.php +++ b/app/Models/FeedDAO.php @@ -19,7 +19,8 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { return false; } - protected function autoUpdateDb(array $errorInfo) { + /** @param array<string> $errorInfo */ + protected function autoUpdateDb(array $errorInfo): bool { if (isset($errorInfo[0])) { if ($errorInfo[0] === FreshRSS_DatabaseDAO::ER_BAD_FIELD_ERROR || $errorInfo[0] === FreshRSS_DatabaseDAOPGSQL::UNDEFINED_COLUMN) { $errorLines = explode("\n", $errorInfo[2], 2); // The relevant column name is on the first line, other lines are noise diff --git a/app/Models/FeedDAOSQLite.php b/app/Models/FeedDAOSQLite.php index a4432ea62..08a352d5f 100644 --- a/app/Models/FeedDAOSQLite.php +++ b/app/Models/FeedDAOSQLite.php @@ -2,7 +2,8 @@ class FreshRSS_FeedDAOSQLite extends FreshRSS_FeedDAO { - protected function autoUpdateDb(array $errorInfo) { + /** @param array<string> $errorInfo */ + protected function autoUpdateDb(array $errorInfo): bool { if ($tableInfo = $this->pdo->query("PRAGMA table_info('feed')")) { $columns = $tableInfo->fetchAll(PDO::FETCH_COLUMN, 1); foreach (['attributes', 'kind'] as $column) { diff --git a/app/Models/ReadingMode.php b/app/Models/ReadingMode.php index ddb413315..6f2fc889c 100644 --- a/app/Models/ReadingMode.php +++ b/app/Models/ReadingMode.php @@ -28,12 +28,9 @@ class FreshRSS_ReadingMode { /** * ReadingMode constructor. - * @param string $id - * @param string $title - * @param string[] $urlParams - * @param bool $active + * @param array<string> $urlParams */ - public function __construct($id, $title, $urlParams, $active) { + public function __construct(string $id, string $title, array $urlParams, bool $active) { $this->id = $id; $this->name = _i($id); $this->title = $title; @@ -41,41 +38,24 @@ class FreshRSS_ReadingMode { $this->isActive = $active; } - /** - * @return string - */ - public function getId() { + public function getId(): string { return $this->id; } - /** - * @return string - */ - public function getName() { + public function getName(): string { return $this->name; } - /** - * @param string $name - * @return FreshRSS_ReadingMode - */ - public function setName($name) { + public function setName(string $name): FreshRSS_ReadingMode { $this->name = $name; return $this; } - /** - * @return string - */ - public function getTitle() { + public function getTitle(): string { return $this->title; } - /** - * @param string $title - * @return FreshRSS_ReadingMode - */ - public function setTitle($title) { + public function setTitle(string $title): FreshRSS_ReadingMode { $this->title = $title; return $this; } @@ -83,40 +63,31 @@ class FreshRSS_ReadingMode { /** * @return array<string> */ - public function getUrlParams() { + public function getUrlParams(): array { return $this->urlParams; } /** * @param array<string> $urlParams - * @return FreshRSS_ReadingMode */ - public function setUrlParams($urlParams) { + public function setUrlParams(array $urlParams): FreshRSS_ReadingMode { $this->urlParams = $urlParams; return $this; } - /** - * @return bool - */ - public function isActive() { + public function isActive(): bool { return $this->isActive; } - /** - * @param bool $isActive - * @return FreshRSS_ReadingMode - */ - public function setIsActive($isActive) { + public function setIsActive(bool $isActive): FreshRSS_ReadingMode { $this->isActive = $isActive; return $this; } /** - * Returns the built-in reading modes. - * return ReadingMode[] + * @return array<FreshRSS_ReadingMode> the built-in reading modes */ - public static function getReadingModes() { + public static function getReadingModes(): array { $actualView = Minz_Request::actionName(); $defaultCtrl = Minz_Request::defaultControllerName(); $isDefaultCtrl = Minz_Request::controllerName() === $defaultCtrl; diff --git a/app/Models/TagDAO.php b/app/Models/TagDAO.php index ca927ef38..8dc392160 100644 --- a/app/Models/TagDAO.php +++ b/app/Models/TagDAO.php @@ -30,7 +30,8 @@ class FreshRSS_TagDAO extends Minz_ModelPdo { return $ok; } - protected function autoUpdateDb(array $errorInfo) { + /** @param array<string> $errorInfo */ + protected function autoUpdateDb(array $errorInfo): bool { if (isset($errorInfo[0])) { if ($errorInfo[0] === FreshRSS_DatabaseDAO::ER_BAD_TABLE_ERROR || $errorInfo[0] === FreshRSS_DatabaseDAOPGSQL::UNDEFINED_TABLE) { if (stripos($errorInfo[2], 'tag') !== false) { diff --git a/app/Models/TagDAOSQLite.php b/app/Models/TagDAOSQLite.php index 530669699..910455546 100644 --- a/app/Models/TagDAOSQLite.php +++ b/app/Models/TagDAOSQLite.php @@ -6,7 +6,8 @@ class FreshRSS_TagDAOSQLite extends FreshRSS_TagDAO { return 'OR IGNORE'; } - protected function autoUpdateDb(array $errorInfo) { + /** @param array<string> $errorInfo */ + protected function autoUpdateDb(array $errorInfo): bool { if ($tableInfo = $this->pdo->query("SELECT sql FROM sqlite_master where name='tag'")) { $showCreate = $tableInfo->fetchColumn(); if (stripos($showCreate, 'tag') === false) { diff --git a/app/Models/UserDAO.php b/app/Models/UserDAO.php index 9f91df80e..8ba50cc29 100644 --- a/app/Models/UserDAO.php +++ b/app/Models/UserDAO.php @@ -1,7 +1,8 @@ <?php class FreshRSS_UserDAO extends Minz_ModelPdo { - public function createUser() { + + public function createUser(): bool { require(APP_PATH . '/SQL/install.sql.' . $this->pdo->dbType() . '.php'); try { @@ -21,7 +22,7 @@ class FreshRSS_UserDAO extends Minz_ModelPdo { } } - public function deleteUser() { + public function deleteUser(): bool { if (defined('STDERR')) { fwrite(STDERR, 'Deleting SQL data for user “' . $this->current_user . "”…\n"); } @@ -38,18 +39,18 @@ class FreshRSS_UserDAO extends Minz_ModelPdo { } } - public static function exists($username) { + public static function exists(string $username): bool { return is_dir(USERS_PATH . '/' . $username); } - public static function touch($username = '') { + public static function touch(string $username = ''): bool { if (!FreshRSS_user_Controller::checkUsername($username)) { $username = Minz_User::name() ?? Minz_User::INTERNAL_USER; } return touch(USERS_PATH . '/' . $username . '/config.php'); } - public static function mtime($username) { - return @filemtime(USERS_PATH . '/' . $username . '/config.php'); + public static function mtime(string $username): int { + return @(int)filemtime(USERS_PATH . '/' . $username . '/config.php'); } } |
