aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2024-04-10 15:33:43 +0200
committerGravatar GitHub <noreply@github.com> 2024-04-10 15:33:43 +0200
commit350edf398c55b472e19a3017de9b4d2d3420b9e4 (patch)
tree00672f4cba0830e4b39f778e3a36de6b961fc5bb /app/Models
parent8280e3d88edb93211fcf2aec15a7b4c1ae4d3813 (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/Models')
-rw-r--r--app/Models/BooleanSearch.php1
-rw-r--r--app/Models/CategoryDAOSQLite.php1
-rw-r--r--app/Models/DatabaseDAOPGSQL.php6
-rw-r--r--app/Models/DatabaseDAOSQLite.php7
-rw-r--r--app/Models/EntryDAOPGSQL.php6
-rw-r--r--app/Models/EntryDAOSQLite.php9
-rw-r--r--app/Models/FeedDAOSQLite.php1
-rw-r--r--app/Models/Search.php1
-rw-r--r--app/Models/StatsDAOPGSQL.php4
-rw-r--r--app/Models/StatsDAOSQLite.php2
-rw-r--r--app/Models/TagDAOPGSQL.php1
-rw-r--r--app/Models/TagDAOSQLite.php1
12 files changed, 39 insertions, 1 deletions
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';
}