diff options
| author | 2022-02-05 11:47:28 +0100 | |
|---|---|---|
| committer | 2022-02-05 11:47:28 +0100 | |
| commit | 87b181af21ad3644e30bdf44b6704083c8a391a2 (patch) | |
| tree | 1989db531aebf9b29ccb8ce2f1e9c4a1e43cf22d /app/Models/DatabaseDAOSQLite.php | |
| parent | 4d5f3a20c0fee4f4fde160cc3a811289429795e1 (diff) | |
Draft:Add interface and add typehinting (#4130)
* Add interface and add typehinting
* Simplify and complete
* inheritdoc
Co-authored-by: Luc SANCHEZ <l.sanchez-ext@ubitransport.com>
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Diffstat (limited to 'app/Models/DatabaseDAOSQLite.php')
| -rw-r--r-- | app/Models/DatabaseDAOSQLite.php | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/app/Models/DatabaseDAOSQLite.php b/app/Models/DatabaseDAOSQLite.php index f944ec043..e5a6f5a04 100644 --- a/app/Models/DatabaseDAOSQLite.php +++ b/app/Models/DatabaseDAOSQLite.php @@ -4,7 +4,8 @@ * This class is used to test database is well-constructed (SQLite). */ class FreshRSS_DatabaseDAOSQLite extends FreshRSS_DatabaseDAO { - public function tablesAreCorrect() { + + public function tablesAreCorrect(): bool { $sql = 'SELECT name FROM sqlite_master WHERE type="table"'; $stm = $this->pdo->query($sql); $res = $stm->fetchAll(PDO::FETCH_ASSOC); @@ -24,36 +25,36 @@ class FreshRSS_DatabaseDAOSQLite extends FreshRSS_DatabaseDAO { return count(array_keys($tables, true, true)) == count($tables); } - public function getSchema($table) { + public function getSchema(string $table): array { $sql = 'PRAGMA table_info(' . $table . ')'; $stm = $this->pdo->query($sql); return $this->listDaoToSchema($stm->fetchAll(PDO::FETCH_ASSOC)); } - public function entryIsCorrect() { + public function entryIsCorrect(): bool { return $this->checkTable('entry', array( 'id', 'guid', 'title', 'author', 'content', 'link', 'date', 'lastSeen', 'hash', 'is_read', 'is_favorite', 'id_feed', 'tags', )); } - public function entrytmpIsCorrect() { + public function entrytmpIsCorrect(): bool { return $this->checkTable('entrytmp', array( 'id', 'guid', 'title', 'author', 'content', 'link', 'date', 'lastSeen', 'hash', 'is_read', 'is_favorite', 'id_feed', 'tags', )); } - public function daoToSchema($dao) { - return array( - 'name' => $dao['name'], - 'type' => strtolower($dao['type']), + public function daoToSchema(array $dao): array { + return [ + 'name' => $dao['name'], + 'type' => strtolower($dao['type']), 'notnull' => $dao['notnull'] === '1' ? true : false, 'default' => $dao['dflt_value'], - ); + ]; } - public function size($all = false) { + public function size(bool $all = false): int { $sum = 0; if ($all) { foreach (glob(DATA_PATH . '/users/*/db.sqlite') as $filename) { @@ -62,10 +63,10 @@ class FreshRSS_DatabaseDAOSQLite extends FreshRSS_DatabaseDAO { } else { $sum = @filesize(DATA_PATH . '/users/' . $this->current_user . '/db.sqlite'); } - return $sum; + return intval($sum); } - public function optimize() { + public function optimize(): bool { $ok = $this->pdo->exec('VACUUM') !== false; if (!$ok) { $info = $this->pdo->errorInfo(); |
