diff options
| author | 2024-04-10 15:33:43 +0200 | |
|---|---|---|
| committer | 2024-04-10 15:33:43 +0200 | |
| commit | 350edf398c55b472e19a3017de9b4d2d3420b9e4 (patch) | |
| tree | 00672f4cba0830e4b39f778e3a36de6b961fc5bb /app | |
| parent | 8280e3d88edb93211fcf2aec15a7b4c1ae4d3813 (diff) | |
PHP 8.3 #[\Override] (#6273)
* PHP 8.3 #[\Override]
https://php.watch/versions/8.3/override-attr
With PHPStan `checkMissingOverrideMethodAttribute` https://phpstan.org/config-reference#checkmissingoverridemethodattribute
And modified the call to phpstan-next on the model of https://github.com/FreshRSS/Extensions/pull/228 (more robust than the find method, which gave some strange errors)
* Update extension example accordingly
Diffstat (limited to 'app')
24 files changed, 51 insertions, 1 deletions
diff --git a/app/Controllers/categoryController.php b/app/Controllers/categoryController.php index 780f03f02..410147b4e 100644 --- a/app/Controllers/categoryController.php +++ b/app/Controllers/categoryController.php @@ -12,6 +12,7 @@ class FreshRSS_category_Controller extends FreshRSS_ActionController { * underlying framework. * */ + #[\Override] public function firstAction(): void { if (!FreshRSS_Auth::hasAccess()) { Minz_Error::error(403); diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php index e7f877428..4fd9a2f28 100644 --- a/app/Controllers/configureController.php +++ b/app/Controllers/configureController.php @@ -10,6 +10,7 @@ class FreshRSS_configure_Controller extends FreshRSS_ActionController { * the common boilerplate for every action. It is triggered by the * underlying framework. */ + #[\Override] public function firstAction(): void { if (!FreshRSS_Auth::hasAccess()) { Minz_Error::error(403); diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php index c30c6b6fa..38dbf8317 100644 --- a/app/Controllers/entryController.php +++ b/app/Controllers/entryController.php @@ -16,6 +16,7 @@ class FreshRSS_entry_Controller extends FreshRSS_ActionController { * the common boilerplate for every action. It is triggered by the * underlying framework. */ + #[\Override] public function firstAction(): void { if (!FreshRSS_Auth::hasAccess()) { Minz_Error::error(403); diff --git a/app/Controllers/extensionController.php b/app/Controllers/extensionController.php index 8b01b5823..0029d5e52 100644 --- a/app/Controllers/extensionController.php +++ b/app/Controllers/extensionController.php @@ -10,6 +10,7 @@ class FreshRSS_extension_Controller extends FreshRSS_ActionController { * the common boiler plate for every action. It is triggered by the * underlying framework. */ + #[\Override] public function firstAction(): void { if (!FreshRSS_Auth::hasAccess()) { Minz_Error::error(403); diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 122807cf0..d1d506c0d 100644 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -10,6 +10,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController { * the common boiler plate for every action. It is triggered by the * underlying framework. */ + #[\Override] public function firstAction(): void { if (!FreshRSS_Auth::hasAccess()) { // Token is useful in the case that anonymous refresh is forbidden diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 2a437e34c..f92abf69d 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -15,6 +15,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { * the common boilerplate for every action. It is triggered by the * underlying framework. */ + #[\Override] public function firstAction(): void { if (!FreshRSS_Auth::hasAccess()) { Minz_Error::error(403); diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index 17439fe27..65e30c4bd 100644 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -6,6 +6,7 @@ declare(strict_types=1); */ class FreshRSS_index_Controller extends FreshRSS_ActionController { + #[\Override] public function firstAction(): void { $this->view->html_url = Minz_Url::display(['c' => 'index', 'a' => 'index'], 'html', 'root'); } diff --git a/app/Controllers/javascriptController.php b/app/Controllers/javascriptController.php index f7ac5a852..2cdf75d03 100644 --- a/app/Controllers/javascriptController.php +++ b/app/Controllers/javascriptController.php @@ -12,6 +12,7 @@ class FreshRSS_javascript_Controller extends FreshRSS_ActionController { parent::__construct(FreshRSS_ViewJavascript::class); } + #[\Override] public function firstAction(): void { $this->view->_layout(null); } diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.php index 8ff2744ae..062603930 100644 --- a/app/Controllers/statsController.php +++ b/app/Controllers/statsController.php @@ -20,6 +20,7 @@ class FreshRSS_stats_Controller extends FreshRSS_ActionController { * the common boilerplate for every action. It is triggered by the * underlying framework. */ + #[\Override] public function firstAction(): void { if (!FreshRSS_Auth::hasAccess()) { Minz_Error::error(403); diff --git a/app/Controllers/subscriptionController.php b/app/Controllers/subscriptionController.php index 554243725..39836d1e4 100644 --- a/app/Controllers/subscriptionController.php +++ b/app/Controllers/subscriptionController.php @@ -10,6 +10,7 @@ class FreshRSS_subscription_Controller extends FreshRSS_ActionController { * the common boilerplate for every action. It is triggered by the * underlying framework. */ + #[\Override] public function firstAction(): void { if (!FreshRSS_Auth::hasAccess()) { Minz_Error::error(403); diff --git a/app/Controllers/tagController.php b/app/Controllers/tagController.php index d998045a4..02bb930ee 100644 --- a/app/Controllers/tagController.php +++ b/app/Controllers/tagController.php @@ -16,6 +16,7 @@ class FreshRSS_tag_Controller extends FreshRSS_ActionController { * the common boilerplate for every action. It is triggered by the * underlying framework. */ + #[\Override] public function firstAction(): void { // If ajax request, we do not print layout $this->ajax = Minz_Request::paramBoolean('ajax'); diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php index eeac7eb09..3f4a46e6a 100644 --- a/app/Controllers/updateController.php +++ b/app/Controllers/updateController.php @@ -113,6 +113,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController { return $return == 0 ? true : 'Git error: ' . $line; } + #[\Override] public function firstAction(): void { if (!FreshRSS_Auth::hasAccess('admin')) { Minz_Error::error(403); diff --git a/app/Models/BooleanSearch.php b/app/Models/BooleanSearch.php index dd8b95efb..898ffa3bc 100644 --- a/app/Models/BooleanSearch.php +++ b/app/Models/BooleanSearch.php @@ -291,6 +291,7 @@ class FreshRSS_BooleanSearch { $this->searches[] = $search; } + #[\Override] public function __toString(): string { return $this->getRawInput(); } diff --git a/app/Models/CategoryDAOSQLite.php b/app/Models/CategoryDAOSQLite.php index 268d579b1..5fb0da31d 100644 --- a/app/Models/CategoryDAOSQLite.php +++ b/app/Models/CategoryDAOSQLite.php @@ -4,6 +4,7 @@ declare(strict_types=1); class FreshRSS_CategoryDAOSQLite extends FreshRSS_CategoryDAO { /** @param array<int|string> $errorInfo */ + #[\Override] protected function autoUpdateDb(array $errorInfo): bool { if ($tableInfo = $this->pdo->query("PRAGMA table_info('category')")) { $columns = $tableInfo->fetchAll(PDO::FETCH_COLUMN, 1); diff --git a/app/Models/DatabaseDAOPGSQL.php b/app/Models/DatabaseDAOPGSQL.php index fe3d6149d..e6895e6f1 100644 --- a/app/Models/DatabaseDAOPGSQL.php +++ b/app/Models/DatabaseDAOPGSQL.php @@ -10,6 +10,7 @@ class FreshRSS_DatabaseDAOPGSQL extends FreshRSS_DatabaseDAOSQLite { public const UNDEFINED_COLUMN = '42703'; public const UNDEFINED_TABLE = '42P01'; + #[\Override] public function tablesAreCorrect(): bool { $db = FreshRSS_Context::systemConf()->db; $sql = 'SELECT * FROM pg_catalog.pg_tables where tableowner=:tableowner'; @@ -34,6 +35,7 @@ class FreshRSS_DatabaseDAOPGSQL extends FreshRSS_DatabaseDAOSQLite { } /** @return array<array<string,string|int|bool|null>> */ + #[\Override] public function getSchema(string $table): array { $sql = <<<'SQL' SELECT column_name AS field, data_type AS type, column_default AS default, is_nullable AS null @@ -47,6 +49,7 @@ SQL; * @param array<string,string|int|bool|null> $dao * @return array{'name':string,'type':string,'notnull':bool,'default':mixed} */ + #[\Override] public function daoToSchema(array $dao): array { return [ 'name' => (string)($dao['field']), @@ -56,6 +59,7 @@ SQL; ]; } + #[\Override] public function size(bool $all = false): int { if ($all) { $db = FreshRSS_Context::systemConf()->db; @@ -75,7 +79,7 @@ SQL; return (int)($res[0] ?? -1); } - + #[\Override] public function optimize(): bool { $ok = true; $tables = ['category', 'feed', 'entry', 'entrytmp', 'tag', 'entrytag']; diff --git a/app/Models/DatabaseDAOSQLite.php b/app/Models/DatabaseDAOSQLite.php index e72cc74e8..0ac6ee8f5 100644 --- a/app/Models/DatabaseDAOSQLite.php +++ b/app/Models/DatabaseDAOSQLite.php @@ -6,6 +6,7 @@ declare(strict_types=1); */ class FreshRSS_DatabaseDAOSQLite extends FreshRSS_DatabaseDAO { + #[\Override] public function tablesAreCorrect(): bool { $sql = 'SELECT name FROM sqlite_master WHERE type="table"'; $stm = $this->pdo->query($sql); @@ -30,18 +31,21 @@ class FreshRSS_DatabaseDAOSQLite extends FreshRSS_DatabaseDAO { } /** @return array<array<string,string|int|bool|null>> */ + #[\Override] public function getSchema(string $table): array { $sql = 'PRAGMA table_info(' . $table . ')'; $stm = $this->pdo->query($sql); return $stm ? $this->listDaoToSchema($stm->fetchAll(PDO::FETCH_ASSOC) ?: []) : []; } + #[\Override] public function entryIsCorrect(): bool { return $this->checkTable('entry', [ 'id', 'guid', 'title', 'author', 'content', 'link', 'date', 'lastSeen', 'hash', 'is_read', 'is_favorite', 'id_feed', 'tags', ]); } + #[\Override] public function entrytmpIsCorrect(): bool { return $this->checkTable('entrytmp', [ 'id', 'guid', 'title', 'author', 'content', 'link', 'date', 'lastSeen', 'hash', 'is_read', 'is_favorite', 'id_feed', 'tags' @@ -52,6 +56,7 @@ class FreshRSS_DatabaseDAOSQLite extends FreshRSS_DatabaseDAO { * @param array<string,string|int|bool|null> $dao * @return array{'name':string,'type':string,'notnull':bool,'default':mixed} */ + #[\Override] public function daoToSchema(array $dao): array { return [ 'name' => (string)$dao['name'], @@ -61,6 +66,7 @@ class FreshRSS_DatabaseDAOSQLite extends FreshRSS_DatabaseDAO { ]; } + #[\Override] public function size(bool $all = false): int { $sum = 0; if ($all) { @@ -73,6 +79,7 @@ class FreshRSS_DatabaseDAOSQLite extends FreshRSS_DatabaseDAO { return $sum; } + #[\Override] public function optimize(): bool { $ok = $this->pdo->exec('VACUUM') !== false; if (!$ok) { diff --git a/app/Models/EntryDAOPGSQL.php b/app/Models/EntryDAOPGSQL.php index 39e86384d..8adeffe9e 100644 --- a/app/Models/EntryDAOPGSQL.php +++ b/app/Models/EntryDAOPGSQL.php @@ -3,23 +3,28 @@ declare(strict_types=1); class FreshRSS_EntryDAOPGSQL extends FreshRSS_EntryDAOSQLite { + #[\Override] public static function hasNativeHex(): bool { return true; } + #[\Override] public static function sqlHexDecode(string $x): string { return 'decode(' . $x . ", 'hex')"; } + #[\Override] public static function sqlHexEncode(string $x): string { return 'encode(' . $x . ", 'hex')"; } + #[\Override] public static function sqlIgnoreConflict(string $sql): string { return rtrim($sql, ' ;') . ' ON CONFLICT DO NOTHING'; } /** @param array<string|int> $errorInfo */ + #[\Override] 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) { @@ -34,6 +39,7 @@ class FreshRSS_EntryDAOPGSQL extends FreshRSS_EntryDAOSQLite { return false; } + #[\Override] public function commitNewEntries(): bool { //TODO: Update to PostgreSQL 9.5+ syntax with ON CONFLICT DO NOTHING $sql = 'DO $$ diff --git a/app/Models/EntryDAOSQLite.php b/app/Models/EntryDAOSQLite.php index 1a87d03be..91894b8ac 100644 --- a/app/Models/EntryDAOSQLite.php +++ b/app/Models/EntryDAOSQLite.php @@ -3,27 +3,33 @@ declare(strict_types=1); class FreshRSS_EntryDAOSQLite extends FreshRSS_EntryDAO { + #[\Override] public static function isCompressed(): bool { return false; } + #[\Override] public static function hasNativeHex(): bool { return false; } + #[\Override] protected static function sqlConcat(string $s1, string $s2): string { return $s1 . '||' . $s2; } + #[\Override] public static function sqlHexDecode(string $x): string { return $x; } + #[\Override] public static function sqlIgnoreConflict(string $sql): string { return str_replace('INSERT INTO ', 'INSERT OR IGNORE INTO ', $sql); } /** @param array<string|int> $errorInfo */ + #[\Override] protected function autoUpdateDb(array $errorInfo): bool { if ($tableInfo = $this->pdo->query("PRAGMA table_info('entry')")) { $columns = $tableInfo->fetchAll(PDO::FETCH_COLUMN, 1) ?: []; @@ -36,6 +42,7 @@ class FreshRSS_EntryDAOSQLite extends FreshRSS_EntryDAO { return false; } + #[\Override] public function commitNewEntries(): bool { $sql = <<<'SQL' DROP TABLE IF EXISTS `tmp`; @@ -74,6 +81,7 @@ SQL; * @param bool $is_read * @return int|false affected rows */ + #[\Override] public function markRead($ids, bool $is_read = true) { FreshRSS_UserDAO::touch(); if (is_array($ids)) { //Many IDs at once (used by API) @@ -119,6 +127,7 @@ SQL; * @param string $idMax max article ID * @return int|false affected rows */ + #[\Override] public function markReadTag($id = 0, string $idMax = '0', ?FreshRSS_BooleanSearch $filters = null, int $state = 0, bool $is_read = true) { FreshRSS_UserDAO::touch(); if ($idMax == 0) { diff --git a/app/Models/FeedDAOSQLite.php b/app/Models/FeedDAOSQLite.php index c6bf9c8ae..69b859b79 100644 --- a/app/Models/FeedDAOSQLite.php +++ b/app/Models/FeedDAOSQLite.php @@ -4,6 +4,7 @@ declare(strict_types=1); class FreshRSS_FeedDAOSQLite extends FreshRSS_FeedDAO { /** @param array<int|string> $errorInfo */ + #[\Override] protected function autoUpdateDb(array $errorInfo): bool { if ($tableInfo = $this->pdo->query("PRAGMA table_info('feed')")) { $columns = $tableInfo->fetchAll(PDO::FETCH_COLUMN, 1); diff --git a/app/Models/Search.php b/app/Models/Search.php index d5dd701c3..00cb408f9 100644 --- a/app/Models/Search.php +++ b/app/Models/Search.php @@ -107,6 +107,7 @@ class FreshRSS_Search { $this->parseSearch($input); } + #[\Override] public function __toString(): string { return $this->getRawInput(); } diff --git a/app/Models/StatsDAOPGSQL.php b/app/Models/StatsDAOPGSQL.php index 5204b04e3..4fd00c29d 100644 --- a/app/Models/StatsDAOPGSQL.php +++ b/app/Models/StatsDAOPGSQL.php @@ -9,6 +9,7 @@ class FreshRSS_StatsDAOPGSQL extends FreshRSS_StatsDAO { * @param int $feed id * @return array<int,int> */ + #[\Override] public function calculateEntryRepartitionPerFeedPerHour(?int $feed = null): array { return $this->calculateEntryRepartitionPerFeedPerPeriod('hour', $feed); } @@ -17,6 +18,7 @@ class FreshRSS_StatsDAOPGSQL extends FreshRSS_StatsDAO { * Calculates the number of article per day of week per feed * @return array<int,int> */ + #[\Override] public function calculateEntryRepartitionPerFeedPerDayOfWeek(?int $feed = null): array { return $this->calculateEntryRepartitionPerFeedPerPeriod('day', $feed); } @@ -25,6 +27,7 @@ class FreshRSS_StatsDAOPGSQL extends FreshRSS_StatsDAO { * Calculates the number of article per month per feed * @return array<int,int> */ + #[\Override] public function calculateEntryRepartitionPerFeedPerMonth(?int $feed = null): array { return $this->calculateEntryRepartitionPerFeedPerPeriod('month', $feed); } @@ -34,6 +37,7 @@ class FreshRSS_StatsDAOPGSQL extends FreshRSS_StatsDAO { * @param string $period format string to use for grouping * @return array<int,int> */ + #[\Override] protected function calculateEntryRepartitionPerFeedPerPeriod(string $period, ?int $feed = null): array { $restrict = ''; if ($feed) { diff --git a/app/Models/StatsDAOSQLite.php b/app/Models/StatsDAOSQLite.php index 2aa86f0da..8997f3abe 100644 --- a/app/Models/StatsDAOSQLite.php +++ b/app/Models/StatsDAOSQLite.php @@ -3,6 +3,7 @@ declare(strict_types=1); class FreshRSS_StatsDAOSQLite extends FreshRSS_StatsDAO { + #[\Override] protected function sqlFloor(string $s): string { return "CAST(($s) AS INT)"; } @@ -10,6 +11,7 @@ class FreshRSS_StatsDAOSQLite extends FreshRSS_StatsDAO { /** * @return array<int,int> */ + #[\Override] protected function calculateEntryRepartitionPerFeedPerPeriod(string $period, ?int $feed = null): array { if ($feed) { $restrict = "WHERE e.id_feed = {$feed}"; diff --git a/app/Models/TagDAOPGSQL.php b/app/Models/TagDAOPGSQL.php index de3b20f92..107ab6d08 100644 --- a/app/Models/TagDAOPGSQL.php +++ b/app/Models/TagDAOPGSQL.php @@ -3,6 +3,7 @@ declare(strict_types=1); class FreshRSS_TagDAOPGSQL extends FreshRSS_TagDAO { + #[\Override] public function sqlIgnore(): string { return ''; //TODO } diff --git a/app/Models/TagDAOSQLite.php b/app/Models/TagDAOSQLite.php index efa52807a..2ecda7735 100644 --- a/app/Models/TagDAOSQLite.php +++ b/app/Models/TagDAOSQLite.php @@ -3,6 +3,7 @@ declare(strict_types=1); class FreshRSS_TagDAOSQLite extends FreshRSS_TagDAO { + #[\Override] public function sqlIgnore(): string { return 'OR IGNORE'; } |
