diff options
| author | 2023-07-07 22:36:27 +0200 | |
|---|---|---|
| committer | 2023-07-07 22:36:27 +0200 | |
| commit | f8f163d054110f7e0ff6650fca146b474335f4bd (patch) | |
| tree | dbd831e600bc76ca2830cd417bd52b712ff97309 /app/Models | |
| parent | 7f9594b8c7d7799f2e5f89328bd5981410db8cf0 (diff) | |
Chore/processing of depreciations and updating code to php72 minimum (#5504)
* processing of depreciations and updating of code to php7.2 minimum
* Autoformat many strange array indenting
And revert a few unwanted changes
---------
Co-authored-by: Luc <sanchezluc+freshrss@gmail.com>
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Diffstat (limited to 'app/Models')
| -rw-r--r-- | app/Models/Auth.php | 4 | ||||
| -rw-r--r-- | app/Models/BooleanSearch.php | 10 | ||||
| -rw-r--r-- | app/Models/Category.php | 2 | ||||
| -rw-r--r-- | app/Models/CategoryDAO.php | 20 | ||||
| -rw-r--r-- | app/Models/Context.php | 10 | ||||
| -rw-r--r-- | app/Models/DatabaseDAO.php | 82 | ||||
| -rw-r--r-- | app/Models/DatabaseDAOPGSQL.php | 8 | ||||
| -rw-r--r-- | app/Models/DatabaseDAOSQLite.php | 18 | ||||
| -rw-r--r-- | app/Models/Entry.php | 18 | ||||
| -rw-r--r-- | app/Models/EntryDAO.php | 47 | ||||
| -rw-r--r-- | app/Models/EntryDAOSQLite.php | 18 | ||||
| -rw-r--r-- | app/Models/Feed.php | 126 | ||||
| -rw-r--r-- | app/Models/FeedDAO.php | 56 | ||||
| -rw-r--r-- | app/Models/FilterAction.php | 8 | ||||
| -rw-r--r-- | app/Models/FormAuth.php | 4 | ||||
| -rw-r--r-- | app/Models/ReadingMode.php | 12 | ||||
| -rw-r--r-- | app/Models/Search.php | 2 | ||||
| -rw-r--r-- | app/Models/Share.php | 8 | ||||
| -rw-r--r-- | app/Models/StatsDAO.php | 16 | ||||
| -rw-r--r-- | app/Models/TagDAO.php | 22 | ||||
| -rw-r--r-- | app/Models/Themes.php | 20 | ||||
| -rw-r--r-- | app/Models/UserQuery.php | 4 |
22 files changed, 279 insertions, 236 deletions
diff --git a/app/Models/Auth.php b/app/Models/Auth.php index d048460f6..f3c8b52f9 100644 --- a/app/Models/Auth.php +++ b/app/Models/Auth.php @@ -7,7 +7,7 @@ class FreshRSS_Auth { /** * Determines if user is connected. */ - const DEFAULT_COOKIE_DURATION = 7776000; + public const DEFAULT_COOKIE_DURATION = 7776000; /** @var bool */ private static $login_ok = false; @@ -216,7 +216,7 @@ class FreshRSS_Auth { $csrf = Minz_Session::param('csrf'); if ($csrf == '') { $salt = FreshRSS_Context::$system_conf->salt; - $csrf = sha1($salt . uniqid('' . mt_rand(), true)); + $csrf = sha1($salt . uniqid('' . random_int(0, mt_getrandmax()), true)); Minz_Session::_param('csrf', $csrf); } return $csrf; diff --git a/app/Models/BooleanSearch.php b/app/Models/BooleanSearch.php index d4d8a42ab..5cfcd9342 100644 --- a/app/Models/BooleanSearch.php +++ b/app/Models/BooleanSearch.php @@ -8,7 +8,7 @@ class FreshRSS_BooleanSearch { /** @var string */ private $raw_input = ''; /** @var array<FreshRSS_BooleanSearch|FreshRSS_Search> */ - private $searches = array(); + private $searches = []; /** * @phpstan-var 'AND'|'OR'|'AND NOT' @@ -62,6 +62,9 @@ class FreshRSS_BooleanSearch { $fromS = []; $toS = []; foreach ($all_matches as $matches) { + if (empty($matches['search'])) { + continue; + } for ($i = count($matches['search']) - 1; $i >= 0; $i--) { $name = trim($matches['search'][$i]); if (!empty($queries[$name])) { @@ -97,9 +100,12 @@ class FreshRSS_BooleanSearch { $fromS = []; $toS = []; foreach ($all_matches as $matches) { + if (empty($matches['search'])) { + continue; + } for ($i = count($matches['search']) - 1; $i >= 0; $i--) { // Index starting from 1 - $id = intval(trim($matches['search'][$i])) - 1; + $id = (int)(trim($matches['search'][$i])) - 1; if (!empty($queries[$id])) { $fromS[] = $matches[0][$i]; $toS[] = '(' . trim($queries[$id]->getSearch()) . ')'; diff --git a/app/Models/Category.php b/app/Models/Category.php index c9c919e4a..1adf81f92 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -156,7 +156,7 @@ class FreshRSS_Category extends Minz_Model { /** @param array<FreshRSS_Feed>|FreshRSS_Feed $values */ public function _feeds($values): void { if (!is_array($values)) { - $values = array($values); + $values = [$values]; } $this->feeds = $values; diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php index ccfd5c08a..d617fd672 100644 --- a/app/Models/CategoryDAO.php +++ b/app/Models/CategoryDAO.php @@ -2,7 +2,7 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo { - const DEFAULTCATEGORYID = 1; + public const DEFAULTCATEGORYID = 1; public function resetDefaultCategoryName(): bool { //FreshRSS 1.15.1 @@ -51,7 +51,7 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo { $attributes = []; } if ($keepHistory > 0) { - $attributes['archiving']['keep_min'] = intval($keepHistory); + $attributes['archiving']['keep_min'] = (int)$keepHistory; } elseif ($keepHistory == -1) { //Infinite $attributes['archiving']['keep_period'] = false; $attributes['archiving']['keep_max'] = false; @@ -100,6 +100,7 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo { /** * @param array{'name':string,'id'?:int,'kind'?:int,'lastUpdate'?:int,'error'?:int|bool,'attributes'?:string|array<string,mixed>} $valuesTmp * @return int|false + * @throws JsonException */ public function addCategory(array $valuesTmp) { // TRIM() to provide a type hint as text @@ -115,12 +116,12 @@ SQL; if (!isset($valuesTmp['attributes'])) { $valuesTmp['attributes'] = []; } - $values = array( + $values = [ $valuesTmp['kind'] ?? FreshRSS_Category::KIND_NORMAL, $valuesTmp['name'], is_string($valuesTmp['attributes']) ? $valuesTmp['attributes'] : json_encode($valuesTmp['attributes'], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), $valuesTmp['name'], - ); + ]; if ($stm !== false && $stm->execute($values) && $stm->rowCount() > 0) { $catId = $this->pdo->lastInsertId('`_category_id_seq`'); @@ -153,6 +154,7 @@ SQL; /** * @param array{'name':string,'kind':int,'attributes'?:string|array<string,mixed>} $valuesTmp * @return int|false + * @throws JsonException */ public function updateCategory(int $id, array $valuesTmp) { // No tag of the same name @@ -166,13 +168,13 @@ SQL; if (empty($valuesTmp['attributes'])) { $valuesTmp['attributes'] = []; } - $values = array( + $values = [ $valuesTmp['name'], $valuesTmp['kind'] ?? FreshRSS_Category::KIND_NORMAL, is_string($valuesTmp['attributes']) ? $valuesTmp['attributes'] : json_encode($valuesTmp['attributes'], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), $id, $valuesTmp['name'], - ); + ]; if ($stm !== false && $stm->execute($values)) { return $stm->rowCount(); @@ -358,10 +360,10 @@ SQL; } $stm = $this->pdo->prepare($sql); - $values = array( + $values = [ $cat->id(), $cat->name(), - ); + ]; if ($stm !== false && $stm->execute($values)) { $catId = $this->pdo->lastInsertId('`_category_id_seq`'); @@ -482,7 +484,7 @@ SQL; $cat->_kind($dao['kind']); $cat->_lastUpdate($dao['lastUpdate'] ?? 0); $cat->_error($dao['error'] ?? 0); - $cat->_attributes('', isset($dao['attributes']) ? $dao['attributes'] : ''); + $cat->_attributes('', $dao['attributes'] ?? ''); $list[] = $cat; } diff --git a/app/Models/Context.php b/app/Models/Context.php index c10119d7d..2dc49e844 100644 --- a/app/Models/Context.php +++ b/app/Models/Context.php @@ -18,11 +18,11 @@ final class FreshRSS_Context { /** * @var array<int,FreshRSS_Category> */ - public static $categories = array(); + public static $categories = []; /** * @var array<int,FreshRSS_Tag> */ - public static $tags = array(); + public static $tags = []; /** * @var string */ @@ -261,19 +261,19 @@ final class FreshRSS_Context { return $asArray ? ['s', true] : 's'; } elseif (self::$current_get['feed']) { if ($asArray) { - return array('f', self::$current_get['feed']); + return ['f', self::$current_get['feed']]; } else { return 'f_' . self::$current_get['feed']; } } elseif (self::$current_get['category']) { if ($asArray) { - return array('c', self::$current_get['category']); + return ['c', self::$current_get['category']]; } else { return 'c_' . self::$current_get['category']; } } elseif (self::$current_get['tag']) { if ($asArray) { - return array('t', self::$current_get['tag']); + return ['t', self::$current_get['tag']]; } else { return 't_' . self::$current_get['tag']; } diff --git a/app/Models/DatabaseDAO.php b/app/Models/DatabaseDAO.php index edbfd72cc..ea12bab8e 100644 --- a/app/Models/DatabaseDAO.php +++ b/app/Models/DatabaseDAO.php @@ -6,18 +6,18 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo { //MySQL error codes - const ER_BAD_FIELD_ERROR = '42S22'; - const ER_BAD_TABLE_ERROR = '42S02'; - const ER_DATA_TOO_LONG = '1406'; + public const ER_BAD_FIELD_ERROR = '42S22'; + public const ER_BAD_TABLE_ERROR = '42S02'; + public const ER_DATA_TOO_LONG = '1406'; /** * Based on SQLite SQLITE_MAX_VARIABLE_NUMBER */ - const MAX_VARIABLE_NUMBER = 998; + public const MAX_VARIABLE_NUMBER = 998; //MySQL InnoDB maximum index length for UTF8MB4 //https://dev.mysql.com/doc/refman/8.0/en/innodb-restrictions.html - const LENGTH_INDEX_UNICODE = 191; + public const LENGTH_INDEX_UNICODE = 191; public function create(): string { require(APP_PATH . '/SQL/install.sql.' . $this->pdo->dbType() . '.php'); @@ -53,14 +53,14 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo { return false; } - $tables = array( + $tables = [ $this->pdo->prefix() . 'category' => false, $this->pdo->prefix() . 'feed' => false, $this->pdo->prefix() . 'entry' => false, $this->pdo->prefix() . 'entrytmp' => false, $this->pdo->prefix() . 'tag' => false, $this->pdo->prefix() . 'entrytag' => false, - ); + ]; foreach ($res as $value) { $tables[array_pop($value)] = true; } @@ -90,43 +90,59 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo { } public function categoryIsCorrect(): bool { - return $this->checkTable('category', array( - 'id', 'name', - )); + return $this->checkTable('category', ['id', 'name']); } public function feedIsCorrect(): bool { - return $this->checkTable('feed', array( - 'id', 'url', 'category', 'name', 'website', 'description', 'lastUpdate', - 'priority', 'pathEntries', 'httpAuth', 'error', 'ttl', 'attributes', - 'cache_nbEntries', 'cache_nbUnreads', - )); + return $this->checkTable('feed', [ + 'id', + 'url', + 'category', + 'name', + 'website', + 'description', + 'lastUpdate', + 'priority', + 'pathEntries', + 'httpAuth', + 'error', + 'ttl', + 'attributes', + 'cache_nbEntries', + 'cache_nbUnreads', + ]); } public function entryIsCorrect(): bool { - return $this->checkTable('entry', array( - 'id', 'guid', 'title', 'author', 'content_bin', 'link', 'date', 'lastSeen', 'hash', 'is_read', - 'is_favorite', 'id_feed', 'tags', - )); + return $this->checkTable('entry', [ + 'id', + 'guid', + 'title', + 'author', + 'content_bin', + 'link', + 'date', + 'lastSeen', + 'hash', + 'is_read', + 'is_favorite', + 'id_feed', + 'tags', + ]); } public function entrytmpIsCorrect(): bool { - return $this->checkTable('entrytmp', array( - 'id', 'guid', 'title', 'author', 'content_bin', 'link', 'date', 'lastSeen', 'hash', 'is_read', - 'is_favorite', 'id_feed', 'tags', - )); + return $this->checkTable('entrytmp', [ + 'id', 'guid', 'title', 'author', 'content_bin', 'link', 'date', 'lastSeen', 'hash', 'is_read', 'is_favorite', 'id_feed', 'tags' + ]); } public function tagIsCorrect(): bool { - return $this->checkTable('tag', array( - 'id', 'name', 'attributes', - )); + return $this->checkTable('tag', ['id', 'name', 'attributes']); } public function entrytagIsCorrect(): bool { - return $this->checkTable('entrytag', array( - 'id_tag', 'id_entry', - )); + return $this->checkTable('entrytag', ['id_tag', 'id_entry']); } /** @@ -147,7 +163,7 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo { * @return array<array<string,string|int|bool|null>> */ public function listDaoToSchema(array $listDAO): array { - $list = array(); + $list = []; foreach ($listDAO as $dao) { $list[] = $this->daoToSchema($dao); @@ -174,7 +190,7 @@ SQL; public function optimize(): bool { $ok = true; - $tables = array('category', 'feed', 'entry', 'entrytmp', 'tag', 'entrytag'); + $tables = ['category', 'feed', 'entry', 'entrytmp', 'tag', 'entrytag']; foreach ($tables as $table) { $sql = 'OPTIMIZE TABLE `_' . $table . '`'; //MySQL @@ -219,8 +235,8 @@ SQL; return false; } - const SQLITE_EXPORT = 1; - const SQLITE_IMPORT = 2; + public const SQLITE_EXPORT = 1; + public const SQLITE_IMPORT = 2; public function dbCopy(string $filename, int $mode, bool $clearFirst = false): bool { if (!extension_loaded('pdo_sqlite')) { diff --git a/app/Models/DatabaseDAOPGSQL.php b/app/Models/DatabaseDAOPGSQL.php index 29b16e3dc..7976d5e14 100644 --- a/app/Models/DatabaseDAOPGSQL.php +++ b/app/Models/DatabaseDAOPGSQL.php @@ -6,8 +6,8 @@ class FreshRSS_DatabaseDAOPGSQL extends FreshRSS_DatabaseDAOSQLite { //PostgreSQL error codes - const UNDEFINED_COLUMN = '42703'; - const UNDEFINED_TABLE = '42P01'; + public const UNDEFINED_COLUMN = '42703'; + public const UNDEFINED_TABLE = '42P01'; public function tablesAreCorrect(): bool { $db = FreshRSS_Context::$system_conf->db; @@ -71,13 +71,13 @@ pg_total_relation_size('`{$this->pdo->prefix()}entrytag`') SQL; $res = $this->fetchColumn($sql, 0); } - return intval($res[0] ?? -1); + return (int)($res[0] ?? -1); } public function optimize(): bool { $ok = true; - $tables = array('category', 'feed', 'entry', 'entrytmp', 'tag', 'entrytag'); + $tables = ['category', 'feed', 'entry', 'entrytmp', 'tag', 'entrytag']; foreach ($tables as $table) { $sql = 'VACUUM `_' . $table . '`'; diff --git a/app/Models/DatabaseDAOSQLite.php b/app/Models/DatabaseDAOSQLite.php index 5168f5e19..261932867 100644 --- a/app/Models/DatabaseDAOSQLite.php +++ b/app/Models/DatabaseDAOSQLite.php @@ -13,14 +13,14 @@ class FreshRSS_DatabaseDAOSQLite extends FreshRSS_DatabaseDAO { return false; } - $tables = array( + $tables = [ $this->pdo->prefix() . 'category' => false, $this->pdo->prefix() . 'feed' => false, $this->pdo->prefix() . 'entry' => false, $this->pdo->prefix() . 'entrytmp' => false, $this->pdo->prefix() . 'tag' => false, $this->pdo->prefix() . 'entrytag' => false, - ); + ]; foreach ($res as $value) { $tables[$value['name']] = true; } @@ -36,17 +36,15 @@ class FreshRSS_DatabaseDAOSQLite extends FreshRSS_DatabaseDAO { } 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', - )); + return $this->checkTable('entry', [ + 'id', 'guid', 'title', 'author', 'content', 'link', 'date', 'lastSeen', 'hash', 'is_read', 'is_favorite', 'id_feed', 'tags', + ]); } 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', - )); + return $this->checkTable('entrytmp', [ + 'id', 'guid', 'title', 'author', 'content', 'link', 'date', 'lastSeen', 'hash', 'is_read', 'is_favorite', 'id_feed', 'tags' + ]); } /** diff --git a/app/Models/Entry.php b/app/Models/Entry.php index 86b3899d8..7e10367fa 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -1,11 +1,11 @@ <?php class FreshRSS_Entry extends Minz_Model { - const STATE_READ = 1; - const STATE_NOT_READ = 2; - const STATE_ALL = 3; - const STATE_FAVORITE = 4; - const STATE_NOT_FAVORITE = 8; + public const STATE_READ = 1; + public const STATE_NOT_READ = 2; + public const STATE_ALL = 3; + public const STATE_FAVORITE = 4; + public const STATE_NOT_FAVORITE = 8; /** @var string */ private $id = '0'; @@ -143,7 +143,7 @@ class FreshRSS_Entry extends Minz_Model { $medium = $enclosure['medium'] ?? ''; $mime = $enclosure['type'] ?? ''; - return $elink != '' && $medium === 'image' || strpos($mime, 'image') === 0 || + return ($elink != '' && $medium === 'image') || strpos($mime, 'image') === 0 || ($mime == '' && $length == 0 && preg_match('/[.](avif|gif|jpe?g|png|svg|webp)$/i', $elink)); } @@ -800,7 +800,7 @@ HTML; * 'hash':string,'is_read':?bool,'is_favorite':?bool,'id_feed':int,'tags':string,'attributes':array<string,mixed>} */ public function toArray(): array { - return array( + return [ 'id' => $this->id(), 'guid' => $this->guid(), 'title' => $this->title(), @@ -815,7 +815,7 @@ HTML; 'id_feed' => $this->feedId(), 'tags' => $this->tags(true), 'attributes' => $this->attributes(), - ); + ]; } /** @@ -833,7 +833,7 @@ HTML; * Some clients (tested with News+) would fail if sending too long item content * @var int */ - const API_MAX_COMPAT_CONTENT_LENGTH = 500000; + public const API_MAX_COMPAT_CONTENT_LENGTH = 500000; /** * N.B.: To avoid expensive lookups, ensure to set `$entry->_feed($feed)` before calling this function. diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php index f9bdd7be2..e8a531ec0 100644 --- a/app/Models/EntryDAO.php +++ b/app/Models/EntryDAO.php @@ -313,7 +313,7 @@ SQL; */ public function markFavorite($ids, bool $is_favorite = true) { if (!is_array($ids)) { - $ids = array($ids); + $ids = [$ids]; } if (count($ids) < 1) { return 0; @@ -331,7 +331,7 @@ SQL; $sql = 'UPDATE `_entry` ' . 'SET is_favorite=? ' . 'WHERE id IN (' . str_repeat('?,', count($ids) - 1). '?)'; - $values = array($is_favorite ? 1 : 0); + $values = [$is_favorite ? 1 : 0]; $values = array_merge($values, $ids); $stm = $this->pdo->prepare($sql); if ($stm !== false && $stm->execute($values)) { @@ -361,7 +361,7 @@ UPDATE `_feed` f LEFT OUTER JOIN ( SET f.`cache_nbUnreads` = COALESCE(x.nbUnreads, 0) SQL; $hasWhere = false; - $values = array(); + $values = []; if ($feedId != null) { $sql .= ' WHERE'; $hasWhere = true; @@ -419,7 +419,7 @@ SQL; $sql = 'UPDATE `_entry` ' . 'SET is_read=? ' . 'WHERE id IN (' . str_repeat('?,', count($ids) - 1). '?)'; - $values = array($is_read ? 1 : 0); + $values = [$is_read ? 1 : 0]; $values = array_merge($values, $ids); $stm = $this->pdo->prepare($sql); if (!($stm && $stm->execute($values))) { @@ -437,7 +437,7 @@ SQL; . 'SET e.is_read=?,' . 'f.`cache_nbUnreads`=f.`cache_nbUnreads`' . ($is_read ? '-' : '+') . '1 ' . 'WHERE e.id=? AND e.is_read=?'; - $values = array($is_read ? 1 : 0, $ids, $is_read ? 0 : 1); + $values = [$is_read ? 1 : 0, $ids, $is_read ? 0 : 1]; $stm = $this->pdo->prepare($sql); if ($stm !== false && $stm->execute($values)) { return $stm->rowCount(); @@ -484,9 +484,9 @@ SQL; } elseif ($priorityMin >= 0) { $sql .= ' AND f.priority > ' . intval($priorityMin); } - $values = array($is_read ? 1 : 0, $is_read ? 1 : 0, $idMax); + $values = [$is_read ? 1 : 0, $is_read ? 1 : 0, $idMax]; - list($searchValues, $search) = $this->sqlListEntriesWhere('e.', $filters, $state); + [$searchValues, $search] = $this->sqlListEntriesWhere('e.', $filters, $state); $stm = $this->pdo->prepare($sql . $search); if (!($stm && $stm->execute(array_merge($values, $searchValues)))) { @@ -522,9 +522,9 @@ SQL; $sql = 'UPDATE `_entry` e INNER JOIN `_feed` f ON e.id_feed=f.id ' . 'SET e.is_read=? ' . 'WHERE f.category=? AND e.is_read <> ? AND e.id <= ?'; - $values = array($is_read ? 1 : 0, $id, $is_read ? 1 : 0, $idMax); + $values = [$is_read ? 1 : 0, $id, $is_read ? 1 : 0, $idMax]; - list($searchValues, $search) = $this->sqlListEntriesWhere('e.', $filters, $state); + [$searchValues, $search] = $this->sqlListEntriesWhere('e.', $filters, $state); $stm = $this->pdo->prepare($sql . $search); if (!($stm && $stm->execute(array_merge($values, $searchValues)))) { @@ -564,9 +564,9 @@ SQL; $sql = 'UPDATE `_entry` ' . 'SET is_read=? ' . 'WHERE id_feed=? AND is_read <> ? AND id <= ?'; - $values = array($is_read ? 1 : 0, $id_feed, $is_read ? 1 : 0, $idMax); + $values = [$is_read ? 1 : 0, $id_feed, $is_read ? 1 : 0, $idMax]; - list($searchValues, $search) = $this->sqlListEntriesWhere('', $filters, $state); + [$searchValues, $search] = $this->sqlListEntriesWhere('', $filters, $state); $stm = $this->pdo->prepare($sql . $search); if (!($stm && $stm->execute(array_merge($values, $searchValues)))) { @@ -617,14 +617,14 @@ SQL; . 'WHERE ' . ($id == 0 ? '' : 'et.id_tag = ? AND ') . 'e.is_read <> ? AND e.id <= ?'; - $values = array($is_read ? 1 : 0); + $values = [$is_read ? 1 : 0]; if ($id != 0) { $values[] = $id; } $values[] = $is_read ? 1 : 0; $values[] = $idMax; - list($searchValues, $search) = $this->sqlListEntriesWhere('e.', $filters, $state); + [$searchValues, $search] = $this->sqlListEntriesWhere('e.', $filters, $state); $stm = $this->pdo->prepare($sql . $search); if (!($stm && $stm->execute(array_merge($values, $searchValues)))) { @@ -769,7 +769,7 @@ SQL; } if ($filter instanceof FreshRSS_BooleanSearch) { // BooleanSearches are combined by AND (default) or OR (special case) operator and are recursive - list($filterValues, $filterSearch) = self::sqlBooleanSearch($alias, $filter, $level + 1); + [$filterValues, $filterSearch] = self::sqlBooleanSearch($alias, $filter, $level + 1); $filterSearch = trim($filterSearch); if ($filterSearch !== '') { @@ -1016,7 +1016,7 @@ SQL; int $state = FreshRSS_Entry::STATE_ALL, string $order = 'DESC', string $firstId = '', int $date_min = 0) { $search = ' '; - $values = array(); + $values = []; if ($state & FreshRSS_Entry::STATE_NOT_READ) { if (!($state & FreshRSS_Entry::STATE_READ)) { $search .= 'AND ' . $alias . 'is_read=0 '; @@ -1048,14 +1048,14 @@ SQL; $values[] = $date_min . '000000'; } if ($filters && count($filters->searches()) > 0) { - list($filterValues, $filterSearch) = self::sqlBooleanSearch($alias, $filters); + [$filterValues, $filterSearch] = self::sqlBooleanSearch($alias, $filters); $filterSearch = trim($filterSearch); if ($filterSearch !== '') { $search .= 'AND (' . $filterSearch . ') '; $values = array_merge($values, $filterValues); } } - return array($values, $search); + return [$values, $search]; } /** @@ -1071,7 +1071,7 @@ SQL; $state = FreshRSS_Entry::STATE_ALL; } $where = ''; - $values = array(); + $values = []; switch ($type) { case 'a': //All PRIORITY_MAIN_STREAM $where .= 'f.priority > ' . FreshRSS_Feed::PRIORITY_NORMAL . ' '; @@ -1109,10 +1109,9 @@ SQL; throw new FreshRSS_EntriesGetter_Exception('Bad type in Entry->listByType: [' . $type . ']!'); } - list($searchValues, $search) = $this->sqlListEntriesWhere('e.', $filters, $state, $order, $firstId, $date_min); + [$searchValues, $search] = $this->sqlListEntriesWhere('e.', $filters, $state, $order, $firstId, $date_min); - return array(array_merge($values, $searchValues), - 'SELECT ' + return [array_merge($values, $searchValues), 'SELECT ' . ($type === 'T' ? 'DISTINCT ' : '') . 'e.id FROM `_entry` e ' . 'INNER JOIN `_feed` f ON e.id_feed = f.id ' @@ -1120,7 +1119,7 @@ SQL; . 'WHERE ' . $where . $search . 'ORDER BY e.id ' . $order - . ($limit > 0 ? ' LIMIT ' . intval($limit) : '')); //TODO: See http://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/ + . ($limit > 0 ? ' LIMIT ' . intval($limit) : '')]; //TODO: See http://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/ } /** @@ -1257,7 +1256,7 @@ SQL; $sql = 'SELECT guid, ' . static::sqlHexEncode('hash') . ' AS hex_hash FROM `_entry` WHERE id_feed=? AND guid IN (' . str_repeat('?,', count($guids) - 1). '?)'; $stm = $this->pdo->prepare($sql); - $values = array($id_feed); + $values = [$id_feed]; $values = array_merge($values, $guids); if ($stm !== false && $stm->execute($values)) { $rows = $stm->fetchAll(PDO::FETCH_ASSOC); @@ -1297,7 +1296,7 @@ SQL; if ($mtime <= 0) { $mtime = time(); } - $values = array($mtime, $id_feed); + $values = [$mtime, $id_feed]; $values = array_merge($values, $guids); if ($stm !== false && $stm->execute($values)) { return $stm->rowCount(); diff --git a/app/Models/EntryDAOSQLite.php b/app/Models/EntryDAOSQLite.php index 58a61828b..6abf31a5b 100644 --- a/app/Models/EntryDAOSQLite.php +++ b/app/Models/EntryDAOSQLite.php @@ -86,7 +86,7 @@ SET `cache_nbUnreads`=( WHERE e.id_feed=`_feed`.id AND e.is_read=0) SQL; $hasWhere = false; - $values = array(); + $values = []; if ($feedId != null) { $sql .= ' WHERE'; $hasWhere = true; @@ -135,7 +135,7 @@ SQL; } else { $this->pdo->beginTransaction(); $sql = 'UPDATE `_entry` SET is_read=? WHERE id=? AND is_read=?'; - $values = array($is_read ? 1 : 0, $ids, $is_read ? 0 : 1); + $values = [$is_read ? 1 : 0, $ids, $is_read ? 0 : 1]; $stm = $this->pdo->prepare($sql); if (!($stm && $stm->execute($values))) { $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo(); @@ -147,7 +147,7 @@ SQL; if ($affected > 0) { $sql = 'UPDATE `_feed` SET `cache_nbUnreads`=`cache_nbUnreads`' . ($is_read ? '-' : '+') . '1 ' . 'WHERE id=(SELECT e.id_feed FROM `_entry` e WHERE e.id=?)'; - $values = array($ids); + $values = [$ids]; $stm = $this->pdo->prepare($sql); if (!($stm && $stm->execute($values))) { $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo(); @@ -196,9 +196,9 @@ SQL; } elseif ($priorityMin >= 0) { $sql .= ' AND id_feed IN (SELECT f.id FROM `_feed` f WHERE f.priority > ' . intval($priorityMin) . ')'; } - $values = array($is_read ? 1 : 0, $is_read ? 1 : 0, $idMax); + $values = [$is_read ? 1 : 0, $is_read ? 1 : 0, $idMax]; - list($searchValues, $search) = $this->sqlListEntriesWhere('', $filters, $state); + [$searchValues, $search] = $this->sqlListEntriesWhere('', $filters, $state); $stm = $this->pdo->prepare($sql . $search); if (!($stm && $stm->execute(array_merge($values, $searchValues)))) { @@ -235,9 +235,9 @@ SQL; . 'SET is_read = ? ' . 'WHERE is_read <> ? AND id <= ? AND ' . 'id_feed IN (SELECT f.id FROM `_feed` f WHERE f.category=?)'; - $values = array($is_read ? 1 : 0, $is_read ? 1 : 0, $idMax, $id); + $values = [$is_read ? 1 : 0, $is_read ? 1 : 0, $idMax, $id]; - list($searchValues, $search) = $this->sqlListEntriesWhere('', $filters, $state); + [$searchValues, $search] = $this->sqlListEntriesWhere('', $filters, $state); $stm = $this->pdo->prepare($sql . $search); if (!($stm && $stm->execute(array_merge($values, $searchValues)))) { @@ -271,12 +271,12 @@ SQL; . 'id IN (SELECT et.id_entry FROM `_entrytag` et ' . ($id == 0 ? '' : 'WHERE et.id_tag = ?') . ')'; - $values = array($is_read ? 1 : 0, $is_read ? 1 : 0, $idMax); + $values = [$is_read ? 1 : 0, $is_read ? 1 : 0, $idMax]; if ($id != 0) { $values[] = $id; } - list($searchValues, $search) = $this->sqlListEntriesWhere('e.', $filters, $state); + [$searchValues, $search] = $this->sqlListEntriesWhere('e.', $filters, $state); $stm = $this->pdo->prepare($sql . $search); if (!($stm && $stm->execute(array_merge($values, $searchValues)))) { diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 9b9910bff..2baee9e0d 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -6,36 +6,36 @@ class FreshRSS_Feed extends Minz_Model { * Normal RSS or Atom feed * @var int */ - const KIND_RSS = 0; + public const KIND_RSS = 0; /** * Invalid RSS or Atom feed * @var int */ - const KIND_RSS_FORCED = 2; + public const KIND_RSS_FORCED = 2; /** * Normal HTML with XPath scraping * @var int */ - const KIND_HTML_XPATH = 10; + public const KIND_HTML_XPATH = 10; /** * Normal XML with XPath scraping * @var int */ - const KIND_XML_XPATH = 15; + public const KIND_XML_XPATH = 15; /** * Normal JSON with XPath scraping * @var int */ - const KIND_JSON_XPATH = 20; + public const KIND_JSON_XPATH = 20; - const PRIORITY_MAIN_STREAM = 10; - const PRIORITY_NORMAL = 0; - const PRIORITY_ARCHIVED = -10; + public const PRIORITY_MAIN_STREAM = 10; + public const PRIORITY_NORMAL = 0; + public const PRIORITY_ARCHIVED = -10; - const TTL_DEFAULT = 0; + public const TTL_DEFAULT = 0; - const ARCHIVING_RETENTION_COUNT_LIMIT = 10000; - const ARCHIVING_RETENTION_PERIOD = 'P3M'; + public const ARCHIVING_RETENTION_COUNT_LIMIT = 10000; + public const ARCHIVING_RETENTION_PERIOD = 'P3M'; /** @var int */ private $id = 0; @@ -183,10 +183,10 @@ class FreshRSS_Feed extends Minz_Model { $pass = ''; } - return array( + return [ 'username' => $user, - 'password' => $pass - ); + 'password' => $pass, + ]; } } public function inError(): bool { @@ -422,7 +422,7 @@ class FreshRSS_Feed extends Minz_Model { $subscribe_url = $simplePie->subscribe_url(false); //HTML to HTML-PRE //ENT_COMPAT except '&' - $title = strtr(html_only_entity_decode($simplePie->get_title()), array('<' => '<', '>' => '>', '"' => '"')); + $title = strtr(html_only_entity_decode($simplePie->get_title()), ['<' => '<', '>' => '>', '"' => '"']); $this->_name($title == '' ? $this->url : $title); $this->_website(html_only_entity_decode($simplePie->get_link())); @@ -546,14 +546,30 @@ class FreshRSS_Feed extends Minz_Model { $attributeEnclosure = [ 'url' => $elink, ]; - if ($etitle != '') $attributeEnclosure['title'] = $etitle; - if ($credit != null) $attributeEnclosure['credit'] = $credit->get_name(); - if ($description != '') $attributeEnclosure['description'] = $description; - if ($mime != '') $attributeEnclosure['type'] = $mime; - if ($medium != '') $attributeEnclosure['medium'] = $medium; - if ($length != '') $attributeEnclosure['length'] = intval($length); - if ($height != '') $attributeEnclosure['height'] = intval($height); - if ($width != '') $attributeEnclosure['width'] = intval($width); + if ($etitle != '') { + $attributeEnclosure['title'] = $etitle; + } + if ($credit != null) { + $attributeEnclosure['credit'] = $credit->get_name(); + } + if ($description != '') { + $attributeEnclosure['description'] = $description; + } + if ($mime != '') { + $attributeEnclosure['type'] = $mime; + } + if ($medium != '') { + $attributeEnclosure['medium'] = $medium; + } + if ($length != '') { + $attributeEnclosure['length'] = intval($length); + } + if ($height != '') { + $attributeEnclosure['height'] = intval($height); + } + if ($width != '') { + $attributeEnclosure['width'] = intval($width); + } if (!empty($enclosure->get_thumbnails())) { foreach ($enclosure->get_thumbnails() as $thumbnail) { @@ -589,7 +605,7 @@ class FreshRSS_Feed extends Minz_Model { $authorNames, $content == '' ? '' : $content, $link == '' ? '' : $link, - $date ? $date : time() + $date ?: time() ); $entry->_tags($tags); $entry->_feed($this); @@ -604,6 +620,9 @@ class FreshRSS_Feed extends Minz_Model { } } + /** + * @throws FreshRSS_Context_Exception + */ public function loadHtmlXpath(): ?SimplePie { if ($this->url == '') { return null; @@ -615,7 +634,7 @@ class FreshRSS_Feed extends Minz_Model { // Same naming conventions than https://rss-bridge.github.io/rss-bridge/Bridge_API/XPathAbstract.html // https://rss-bridge.github.io/rss-bridge/Bridge_API/BridgeAbstract.html#collectdata - /** @var array<string,string> */ + /** @var array<string,string> $xPathSettings */ $xPathSettings = $this->attributes('xpath'); $xPathFeedTitle = $xPathSettings['feedTitle'] ?? ''; $xPathItem = $xPathSettings['item'] ?? ''; @@ -689,7 +708,7 @@ class FreshRSS_Feed extends Minz_Model { $item['content'] = $content; } else { // Typed expression, save as-is - $item['content'] = strval($result); + $item['content'] = (string)$result; } } @@ -753,6 +772,7 @@ class FreshRSS_Feed extends Minz_Model { /** * Remember to call updateCachedValue($id_feed) or updateCachedValues() just after. * @return int|false the number of lines affected, or false if not applicable + * @throws JsonException */ public function keepMaxUnread() { $keepMaxUnread = $this->attributes('keep_max_n_unread'); @@ -761,8 +781,7 @@ class FreshRSS_Feed extends Minz_Model { } $keepMaxUnread = (int)$keepMaxUnread; if ($keepMaxUnread > 0 && $this->nbNotRead(false) + $this->nbPendingNotRead > $keepMaxUnread) { - $feedDAO = FreshRSS_Factory::createFeedDao(); - return $feedDAO->keepMaxUnread($this->id(), max(0, $keepMaxUnread - $this->nbPendingNotRead)); + return FreshRSS_Factory::createFeedDao()->keepMaxUnread($this->id(), max(0, $keepMaxUnread - $this->nbPendingNotRead)); } return false; } @@ -865,7 +884,7 @@ class FreshRSS_Feed extends Minz_Model { */ public function filterActions(): array { if (empty($this->filterActions)) { - $this->filterActions = array(); + $this->filterActions = []; $filters = $this->attributes('filters'); if (is_array($filters)) { foreach ($filters as $filter) { @@ -897,9 +916,9 @@ class FreshRSS_Feed extends Minz_Model { public function filtersAction(string $action): array { $action = trim($action); if ($action == '') { - return array(); + return []; } - $filters = array(); + $filters = []; $filterActions = $this->filterActions(); for ($i = count($filterActions) - 1; $i >= 0; $i--) { $filterAction = $filterActions[$i]; @@ -957,10 +976,10 @@ class FreshRSS_Feed extends Minz_Model { for ($k = count($filters) - 1; $k >= 0; $k --) { $filter = $filters[$k]; if ($filter != '') { - $filterAction = FreshRSS_FilterAction::fromJSON(array( - 'search' => $filter, - 'actions' => array($action), - )); + $filterAction = FreshRSS_FilterAction::fromJSON([ + 'search' => $filter, + 'actions' => [$action], + ]); if ($filterAction != null) { $filterActions[] = $filterAction; } @@ -976,7 +995,7 @@ class FreshRSS_Feed extends Minz_Model { //<WebSub> public function pubSubHubbubEnabled(): bool { - $url = $this->selfUrl ? $this->selfUrl : $this->url; + $url = $this->selfUrl ?: $this->url; $hubFilename = PSHB_PATH . '/feeds/' . sha1($url) . '/!hub.json'; if ($hubFile = @file_get_contents($hubFilename)) { $hubJson = json_decode($hubFile, true); @@ -989,10 +1008,10 @@ class FreshRSS_Feed extends Minz_Model { } public function pubSubHubbubError(bool $error = true): bool { - $url = $this->selfUrl ? $this->selfUrl : $this->url; + $url = $this->selfUrl ?: $this->url; $hubFilename = PSHB_PATH . '/feeds/' . sha1($url) . '/!hub.json'; $hubFile = @file_get_contents($hubFilename); - $hubJson = $hubFile ? json_decode($hubFile, true) : array(); + $hubJson = $hubFile ? json_decode($hubFile, true) : []; if (!isset($hubJson['error']) || $hubJson['error'] !== $error) { $hubJson['error'] = $error; file_put_contents($hubFilename, json_encode($hubJson)); @@ -1032,10 +1051,10 @@ class FreshRSS_Feed extends Minz_Model { } else { @mkdir($path, 0770, true); $key = sha1($path . FreshRSS_Context::$system_conf->salt); - $hubJson = array( + $hubJson = [ 'hub' => $this->hubUrl, 'key' => $key, - ); + ]; file_put_contents($hubFilename, json_encode($hubJson)); @mkdir(PSHB_PATH . '/keys/', 0770, true); file_put_contents(PSHB_PATH . '/keys/' . $key . '.txt', $this->selfUrl); @@ -1054,7 +1073,7 @@ class FreshRSS_Feed extends Minz_Model { //Parameter true to subscribe, false to unsubscribe. public function pubSubHubbubSubscribe(bool $state): bool { if ($state) { - $url = $this->selfUrl ? $this->selfUrl : $this->url; + $url = $this->selfUrl ?: $this->url; } else { $url = $this->url; //Always use current URL during unsubscribe } @@ -1081,19 +1100,18 @@ class FreshRSS_Feed extends Minz_Model { } $ch = curl_init(); curl_setopt_array($ch, [ - CURLOPT_URL => $hubJson['hub'], - CURLOPT_RETURNTRANSFER => true, - CURLOPT_POSTFIELDS => http_build_query(array( - 'hub.verify' => 'sync', - 'hub.mode' => $state ? 'subscribe' : 'unsubscribe', - 'hub.topic' => $url, - 'hub.callback' => $callbackUrl, - )), - CURLOPT_USERAGENT => FRESHRSS_USERAGENT, - CURLOPT_MAXREDIRS => 10, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_ENCODING => '', //Enable all encodings - ]); + CURLOPT_URL => $hubJson['hub'], + CURLOPT_RETURNTRANSFER => true, + CURLOPT_POSTFIELDS => http_build_query([ + 'hub.verify' => 'sync', + 'hub.mode' => $state ? 'subscribe' : 'unsubscribe', + 'hub.topic' => $url, 'hub.callback' => $callbackUrl, + ]), + CURLOPT_USERAGENT => FRESHRSS_USERAGENT, + CURLOPT_MAXREDIRS => 10, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_ENCODING => '', //Enable all encodings + ]); $response = curl_exec($ch); $info = curl_getinfo($ch); diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index b9295abe0..dc3a33165 100644 --- a/app/Models/FeedDAO.php +++ b/app/Models/FeedDAO.php @@ -38,6 +38,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { * @param array{'url':string,'kind':int,'category':int,'name':string,'website':string,'description':string,'lastUpdate':int,'priority'?:int, * 'pathEntries'?:string,'httpAuth':string,'error':int|bool,'ttl'?:int,'attributes'?:string|array<string|mixed>} $valuesTmp * @return int|false + * @throws JsonException */ public function addFeed(array $valuesTmp) { $sql = 'INSERT INTO `_feed` (url, kind, category, name, website, description, `lastUpdate`, priority, `pathEntries`, `httpAuth`, error, ttl, attributes) @@ -53,7 +54,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { $valuesTmp['attributes'] = []; } - $values = array( + $values = [ $valuesTmp['url'], $valuesTmp['kind'] ?? FreshRSS_Feed::KIND_RSS, $valuesTmp['category'], @@ -61,13 +62,13 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { $valuesTmp['website'], sanitizeHTML($valuesTmp['description'], '', 1023), $valuesTmp['lastUpdate'], - isset($valuesTmp['priority']) ? intval($valuesTmp['priority']) : FreshRSS_Feed::PRIORITY_MAIN_STREAM, + isset($valuesTmp['priority']) ? (int)$valuesTmp['priority'] : FreshRSS_Feed::PRIORITY_MAIN_STREAM, mb_strcut($valuesTmp['pathEntries'], 0, 511, 'UTF-8'), base64_encode($valuesTmp['httpAuth']), - isset($valuesTmp['error']) ? intval($valuesTmp['error']) : 0, - isset($valuesTmp['ttl']) ? intval($valuesTmp['ttl']) : FreshRSS_Feed::TTL_DEFAULT, + isset($valuesTmp['error']) ? (int)$valuesTmp['error'] : 0, + isset($valuesTmp['ttl']) ? (int)$valuesTmp['ttl'] : FreshRSS_Feed::TTL_DEFAULT, is_string($valuesTmp['attributes']) ? $valuesTmp['attributes'] : json_encode($valuesTmp['attributes'], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), - ); + ]; if ($stm !== false && $stm->execute($values)) { $feedId = $this->pdo->lastInsertId('`_feed_id_seq`'); @@ -87,7 +88,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { // Add feed only if we don’t find it in DB $feed_search = $this->searchByUrl($feed->url()); if (!$feed_search) { - $values = array( + $values = [ 'id' => $feed->id(), 'url' => $feed->url(), 'kind' => $feed->kind(), @@ -101,7 +102,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { 'httpAuth' => $feed->httpAuth(), 'ttl' => $feed->ttl(true), 'attributes' => $feed->attributes(), - ); + ]; $id = $this->addFeed($values); if ($id) { @@ -145,6 +146,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { * @return int|false */ public function updateFeed(int $id, array $valuesTmp) { + $values = []; $originalValues = $valuesTmp; if (isset($valuesTmp['name'])) { $valuesTmp['name'] = mb_strcut(trim($valuesTmp['name']), 0, FreshRSS_DatabaseDAO::LENGTH_INDEX_UNICODE, 'UTF-8'); @@ -195,9 +197,9 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { public function updateFeedAttribute(FreshRSS_Feed $feed, string $key, $value) { $feed->_attributes($key, $value); return $this->updateFeed( - $feed->id(), - array('attributes' => $feed->attributes()) - ); + $feed->id(), + ['attributes' => $feed->attributes()] + ); } /** @@ -206,11 +208,11 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { */ public function updateLastUpdate(int $id, bool $inError = false, int $mtime = 0) { $sql = 'UPDATE `_feed` SET `lastUpdate`=?, error=? WHERE id=?'; - $values = array( + $values = [ $mtime <= 0 ? time() : $mtime, $inError ? 1 : 0, $id, - ); + ]; $stm = $this->pdo->prepare($sql); if ($stm !== false && $stm->execute($values)) { @@ -239,10 +241,10 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { $sql = 'UPDATE `_feed` SET category=? WHERE category=?'; $stm = $this->pdo->prepare($sql); - $values = array( + $values = [ $newCat->id(), - $idOldCat - ); + $idOldCat, + ]; if ($stm !== false && $stm->execute($values)) { return $stm->rowCount(); @@ -258,7 +260,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { $sql = 'DELETE FROM `_feed` WHERE id=?'; $stm = $this->pdo->prepare($sql); - $values = array($id); + $values = [$id]; if ($stm !== false && $stm->execute($values)) { return $stm->rowCount(); @@ -280,7 +282,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { } $stm = $this->pdo->prepare($sql); - $values = array($id); + $values = [$id]; if ($stm !== false && $stm->execute($values)) { return $stm->rowCount(); @@ -376,8 +378,8 @@ SQL; $sql = 'SELECT id, url, kind, name, website, `lastUpdate`, `pathEntries`, `httpAuth`, ttl, attributes ' . 'FROM `_feed` ' . ($defaultCacheDuration < 0 ? '' : 'WHERE ttl >= ' . FreshRSS_Feed::TTL_DEFAULT - . ' AND `lastUpdate` < (' . (time() + 60) - . '-(CASE WHEN ttl=' . FreshRSS_Feed::TTL_DEFAULT . ' THEN ' . intval($defaultCacheDuration) . ' ELSE ttl END)) ') + . ' AND `lastUpdate` < (' . (time() + 60) + . '-(CASE WHEN ttl=' . FreshRSS_Feed::TTL_DEFAULT . ' THEN ' . intval($defaultCacheDuration) . ' ELSE ttl END)) ') . 'ORDER BY `lastUpdate` ' . ($limit < 1 ? '' : 'LIMIT ' . intval($limit)); $stm = $this->pdo->query($sql); @@ -389,7 +391,7 @@ SQL; return $this->listFeedsOrderUpdate($defaultCacheDuration, $limit); } Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info)); - return array(); + return []; } } @@ -416,8 +418,10 @@ SQL; return []; } - /** @var array<int,array{'url':string,'kind':int,'category':int,'name':string,'website':string,'lastUpdate':int, - * 'priority'?:int,'pathEntries'?:string,'httpAuth':string,'error':int,'ttl'?:int,'attributes'?:string}> $res */ + /** + * @var array<int,array{'url':string,'kind':int,'category':int,'name':string,'website':string,'lastUpdate':int, + * 'priority'?:int,'pathEntries'?:string,'httpAuth':string,'error':int,'ttl'?:int,'attributes'?:string}> $res + */ $feeds = self::daoToFeed($res); usort($feeds, static function (FreshRSS_Feed $a, FreshRSS_Feed $b) { @@ -579,7 +583,7 @@ SQL; * @return array<int,FreshRSS_Feed> */ public static function daoToFeed(array $listDAO, ?int $catID = null): array { - $list = array(); + $list = []; foreach ($listDAO as $key => $dao) { if (!isset($dao['name'])) { @@ -621,7 +625,7 @@ SQL; public function updateTTL(): void { $sql = 'UPDATE `_feed` SET ttl=:new_value WHERE ttl=:old_value'; $stm = $this->pdo->prepare($sql); - if (!($stm && $stm->execute(array(':new_value' => FreshRSS_Feed::TTL_DEFAULT, ':old_value' => -2)))) { + if (!($stm && $stm->execute([':new_value' => FreshRSS_Feed::TTL_DEFAULT, ':old_value' => -2]))) { $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo(); Minz_Log::error('SQL error ' . __METHOD__ . ' A ' . json_encode($info)); @@ -632,7 +636,7 @@ SQL; Minz_Log::error('SQL error ' . __METHOD__ . ' B ' . json_encode($info)); } } else { - $stm->execute(array(':new_value' => -3600, ':old_value' => -1)); + $stm->execute([':new_value' => -3600, ':old_value' => -1]); } } @@ -643,6 +647,6 @@ SQL; return -1; } $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0); - return isset($res[0]) ? $res[0] : 0; + return $res[0] ?? 0; } } diff --git a/app/Models/FilterAction.php b/app/Models/FilterAction.php index 44ff5674a..e94456086 100644 --- a/app/Models/FilterAction.php +++ b/app/Models/FilterAction.php @@ -34,10 +34,10 @@ class FreshRSS_FilterAction { /** @return array{'search'?:string,'actions'?:array<string>} */ public function toJSON(): array { if (is_array($this->actions) && $this->booleanSearch != null) { - return array( - 'search' => $this->booleanSearch->getRawInput(), - 'actions' => $this->actions, - ); + return [ + 'search' => $this->booleanSearch->getRawInput(), + 'actions' => $this->actions, + ]; } return []; } diff --git a/app/Models/FormAuth.php b/app/Models/FormAuth.php index 52c75d73d..c19856c37 100644 --- a/app/Models/FormAuth.php +++ b/app/Models/FormAuth.php @@ -17,7 +17,7 @@ class FreshRSS_FormAuth { public static function getCredentialsFromCookie(): array { $token = Minz_Session::getLongTermCookie('FreshRSS_login'); if (!ctype_alnum($token)) { - return array(); + return []; } $token_file = DATA_PATH . '/tokens/' . $token . '.txt'; @@ -27,7 +27,7 @@ class FreshRSS_FormAuth { if ($mtime + $cookie_duration < time()) { // Token has expired (> cookie_duration) or does not exist. @unlink($token_file); - return array(); + return []; } $credentials = @file_get_contents($token_file); diff --git a/app/Models/ReadingMode.php b/app/Models/ReadingMode.php index 30ab13aad..c0fa95b31 100644 --- a/app/Models/ReadingMode.php +++ b/app/Models/ReadingMode.php @@ -87,26 +87,26 @@ class FreshRSS_ReadingMode { $isDefaultCtrl = Minz_Request::controllerName() === $defaultCtrl; $urlOutput = Minz_Request::currentRequest(); - $readingModes = array( + $readingModes = [ new FreshRSS_ReadingMode( "view-normal", _t('index.menu.normal_view'), - array_merge($urlOutput, array('c' => $defaultCtrl, 'a' => 'normal')), + array_merge($urlOutput, ['c' => $defaultCtrl, 'a' => 'normal']), ($isDefaultCtrl && $actualView === 'normal') ), new FreshRSS_ReadingMode( "view-global", _t('index.menu.global_view'), - array_merge($urlOutput, array('c' => $defaultCtrl, 'a' => 'global')), + array_merge($urlOutput, ['c' => $defaultCtrl, 'a' => 'global']), ($isDefaultCtrl && $actualView === 'global') ), new FreshRSS_ReadingMode( "view-reader", _t('index.menu.reader_view'), - array_merge($urlOutput, array('c' => $defaultCtrl, 'a' => 'reader')), + array_merge($urlOutput, ['c' => $defaultCtrl, 'a' => 'reader']), ($isDefaultCtrl && $actualView === 'reader') - ), - ); + ) + ]; return $readingModes; } diff --git a/app/Models/Search.php b/app/Models/Search.php index 9622e18ab..52b000344 100644 --- a/app/Models/Search.php +++ b/app/Models/Search.php @@ -645,7 +645,7 @@ class FreshRSS_Search { return ''; } if (preg_match_all('/(?<=\s|^)[!-](?P<search>[^\s]+)/', $input, $matches)) { - $this->not_search = array_merge(is_array($this->not_search) ? $this->not_search : array(), $matches['search']); + $this->not_search = array_merge(is_array($this->not_search) ? $this->not_search : [], $matches['search']); $input = str_replace($matches[0], '', $input); } $this->not_search = self::removeEmptyValues($this->not_search); diff --git a/app/Models/Share.php b/app/Models/Share.php index 4af9c8217..5bacfc381 100644 --- a/app/Models/Share.php +++ b/app/Models/Share.php @@ -254,18 +254,18 @@ class FreshRSS_Share { * Return the current url by merging url_transform and base_url. */ public function url(): string { - $matches = array( + $matches = [ '~ID~', '~URL~', '~TITLE~', '~LINK~', - ); - $replaces = array( + ]; + $replaces = [ $this->id(), $this->base_url, $this->title(), $this->link(), - ); + ]; return str_replace($matches, $replaces, $this->url_transform); } diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.php index 53219843e..122ca14a8 100644 --- a/app/Models/StatsDAO.php +++ b/app/Models/StatsDAO.php @@ -2,7 +2,7 @@ class FreshRSS_StatsDAO extends Minz_ModelPdo { - const ENTRY_COUNT_PERIOD = 30; + public const ENTRY_COUNT_PERIOD = 30; protected function sqlFloor(string $s): string { return "FLOOR($s)"; @@ -14,10 +14,10 @@ class FreshRSS_StatsDAO extends Minz_ModelPdo { * @return array{'main_stream':array{'total':int,'count_unreads':int,'count_reads':int,'count_favorites':int}|false,'all_feeds':array{'total':int,'count_unreads':int,'count_reads':int,'count_favorites':int}|false} */ public function calculateEntryRepartition(): array { - return array( + return [ 'main_stream' => $this->calculateEntryRepartitionPerFeed(null, true), 'all_feeds' => $this->calculateEntryRepartitionPerFeed(null, false), - ); + ]; } /** @@ -313,7 +313,7 @@ SQL; * @return array<string> */ public function getDays(): array { - return $this->convertToTranslatedJson(array( + return $this->convertToTranslatedJson([ 'sun', 'mon', 'tue', @@ -321,7 +321,7 @@ SQL; 'thu', 'fri', 'sat', - )); + ]); } /** @@ -329,7 +329,7 @@ SQL; * @return array<string> */ public function getMonths(): array { - return $this->convertToTranslatedJson(array( + return $this->convertToTranslatedJson([ 'jan', 'feb', 'mar', @@ -342,7 +342,7 @@ SQL; 'oct', 'nov', 'dec', - )); + ]); } /** @@ -350,7 +350,7 @@ SQL; * @param array<string> $data * @return array<string> */ - private function convertToTranslatedJson(array $data = array()): array { + private function convertToTranslatedJson(array $data = []): array { $translated = array_map(static function (string $a) { return _t('gen.date.' . $a); }, $data); diff --git a/app/Models/TagDAO.php b/app/Models/TagDAO.php index 7888caca8..0704fd9f7 100644 --- a/app/Models/TagDAO.php +++ b/app/Models/TagDAO.php @@ -60,11 +60,11 @@ SQL; if (!isset($valuesTmp['attributes'])) { $valuesTmp['attributes'] = []; } - $values = array( + $values = [ $valuesTmp['name'], is_string($valuesTmp['attributes']) ? $valuesTmp['attributes'] : json_encode($valuesTmp['attributes'], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), $valuesTmp['name'], - ); + ]; if ($stm !== false && $stm->execute($values) && $stm->rowCount() > 0) { $tagId = $this->pdo->lastInsertId('`_tag_id_seq`'); @@ -80,10 +80,10 @@ SQL; public function addTagObject(FreshRSS_Tag $tag) { $tag0 = $this->searchByName($tag->name()); if (!$tag0) { - $values = array( + $values = [ 'name' => $tag->name(), 'attributes' => $tag->attributes(), - ); + ]; return $this->addTag($values); } return $tag->id(); @@ -148,7 +148,7 @@ SQL; $sql = 'DELETE FROM `_tag` WHERE id=?'; $stm = $this->pdo->prepare($sql); - $values = array($id); + $values = [$id]; if ($stm !== false && $stm->execute($values)) { return $stm->rowCount(); @@ -326,7 +326,7 @@ SQL; $sql = 'DELETE FROM `_entrytag` WHERE id_tag=? AND id_entry=?'; } $stm = $this->pdo->prepare($sql); - $values = array($id_tag, $id_entry); + $values = [$id_tag, $id_entry]; if ($stm !== false && $stm->execute($values)) { return true; @@ -348,12 +348,12 @@ ORDER BY t.name SQL; $stm = $this->pdo->prepare($sql); - $values = array($id_entry); + $values = [$id_entry]; if ($stm !== false && $stm->execute($values)) { $lines = $stm->fetchAll(PDO::FETCH_ASSOC); for ($i = count($lines) - 1; $i >= 0; $i--) { - $lines[$i]['id'] = intval($lines[$i]['id']); + $lines[$i]['id'] = (int)($lines[$i]['id']); $lines[$i]['checked'] = !empty($lines[$i]['checked']); } return $lines; @@ -377,7 +377,7 @@ FROM `_tag` t INNER JOIN `_entrytag` et ON et.id_tag = t.id SQL; - $values = array(); + $values = []; if (count($entries) > 0) { if (count($entries) > FreshRSS_DatabaseDAO::MAX_VARIABLE_NUMBER) { // Split a query with too many variables parameters @@ -424,12 +424,12 @@ SQL; * @return array<string,array<string>> */ public function getEntryIdsTagNames(array $entries): array { - $result = array(); + $result = []; foreach ($this->getTagsForEntries($entries) ?: [] as $line) { $entryId = 'e_' . $line['id_entry']; $tagName = $line['name']; if (empty($result[$entryId])) { - $result[$entryId] = array(); + $result[$entryId] = []; } $result[$entryId][] = $tagName; } diff --git a/app/Models/Themes.php b/app/Models/Themes.php index 20d825e4b..24539855b 100644 --- a/app/Models/Themes.php +++ b/app/Models/Themes.php @@ -12,14 +12,14 @@ class FreshRSS_Themes extends Minz_Model { public static function getList(): array { return array_values(array_diff( scandir(PUBLIC_PATH . self::$themesUrl) ?: [], - array('..', '.') + ['..', '.'] )); } /** @return array<string,array{'id':string,'name':string,'author':string,'description':string,'version':float|string,'files':array<string>,'theme-color'?:string|array{'dark'?:string,'light'?:string,'default'?:string}}> */ public static function get(): array { $themes_list = self::getList(); - $list = array(); + $list = []; foreach ($themes_list as $theme_dir) { $theme = self::get_infos($theme_dir); if ($theme) { @@ -76,8 +76,8 @@ class FreshRSS_Themes extends Minz_Model { self::$themeIconsUrl = self::$themesUrl . $theme_id . '/icons/'; self::$themeIcons = is_dir(PUBLIC_PATH . self::$themeIconsUrl) ? array_fill_keys(array_diff( scandir(PUBLIC_PATH . self::$themeIconsUrl) ?: [], - array('..', '.') - ), 1) : array(); + ['..', '.'] + ), 1) : []; return $infos; } @@ -89,7 +89,7 @@ class FreshRSS_Themes extends Minz_Model { } public static function alt(string $name): string { - static $alts = array( + static $alts = [ 'add' => '➕', //✚ 'all' => '☰', 'bookmark-add' => '➕', //✚ @@ -131,15 +131,15 @@ class FreshRSS_Themes extends Minz_Model { 'view-global' => '📖', //☷ 'view-reader' => '📜', 'warning' => '⚠️', //△ - ); + ]; return $alts[$name] ?? ''; } // TODO: Change for enum in PHP 8.1+ - const ICON_DEFAULT = 0; - const ICON_IMG = 1; - const ICON_URL = 2; - const ICON_EMOJI = 3; + public const ICON_DEFAULT = 0; + public const ICON_IMG = 1; + public const ICON_URL = 2; + public const ICON_EMOJI = 3; public static function icon(string $name, int $type = self::ICON_DEFAULT): string { $alt = self::alt($name); diff --git a/app/Models/UserQuery.php b/app/Models/UserQuery.php index a4cb469fe..f5e45f6d2 100644 --- a/app/Models/UserQuery.php +++ b/app/Models/UserQuery.php @@ -73,14 +73,14 @@ class FreshRSS_UserQuery { * @return array{'get'?:string,'name'?:string,'order'?:string,'search'?:string,'state'?:int,'url'?:string} */ public function toArray(): array { - return array_filter(array( + return array_filter([ 'get' => $this->get, 'name' => $this->name, 'order' => $this->order, 'search' => $this->search->__toString(), 'state' => $this->state, 'url' => $this->url, - )); + ]); } /** |
