diff options
| author | 2024-09-06 09:06:46 +0200 | |
|---|---|---|
| committer | 2024-09-06 09:06:46 +0200 | |
| commit | a81656c3ed5b8fe0f31794a4fbe0d1a907fca8e8 (patch) | |
| tree | 8bf49bd876aaebc985a9fb1214863190a799cbee /app | |
| parent | 8f7c3473a76809efc88814253722c76f0cc8eb04 (diff) | |
Upgrade to PHP 8.1 (#6711)
* Upgrade to PHP 8.1
As discussed in https://github.com/FreshRSS/FreshRSS/discussions/5474
https://www.php.net/releases/8.0/en.php
https://www.php.net/releases/8.1/en.php
Upgrade to available native type declarations
https://php.net/language.types.declarations
Upgrade to https://phpunit.de/announcements/phpunit-10.html which requires PHP 8.1+ (good timing, as version 9 was not maintained anymore)
Upgrade `:oldest` Docker dev image to oldest Alpine version supporting PHP 8.1: Alpine 3.16, which includes PHP 8.1.22.
* Include 6736
https://github.com/FreshRSS/FreshRSS/pull/6736
Diffstat (limited to 'app')
| -rw-r--r-- | app/Controllers/apiController.php | 3 | ||||
| -rw-r--r-- | app/Controllers/configureController.php | 2 | ||||
| -rw-r--r-- | app/Controllers/feedController.php | 2 | ||||
| -rw-r--r-- | app/Controllers/importExportController.php | 17 | ||||
| -rw-r--r-- | app/Controllers/updateController.php | 2 | ||||
| -rw-r--r-- | app/Models/CategoryDAO.php | 18 | ||||
| -rw-r--r-- | app/Models/Context.php | 2 | ||||
| -rw-r--r-- | app/Models/Entry.php | 19 | ||||
| -rw-r--r-- | app/Models/EntryDAO.php | 30 | ||||
| -rw-r--r-- | app/Models/EntryDAOSQLite.php | 7 | ||||
| -rw-r--r-- | app/Models/Feed.php | 23 | ||||
| -rw-r--r-- | app/Models/FeedDAO.php | 39 | ||||
| -rw-r--r-- | app/Models/FormAuth.php | 6 | ||||
| -rw-r--r-- | app/Models/Search.php | 6 | ||||
| -rw-r--r-- | app/Models/Share.php | 2 | ||||
| -rw-r--r-- | app/Models/StatsDAO.php | 2 | ||||
| -rw-r--r-- | app/Models/Tag.php | 15 | ||||
| -rw-r--r-- | app/Models/TagDAO.php | 32 | ||||
| -rw-r--r-- | app/Models/Themes.php | 4 | ||||
| -rw-r--r-- | app/Services/ExportService.php | 17 | ||||
| -rw-r--r-- | app/Services/ImportService.php | 12 | ||||
| -rw-r--r-- | app/Utils/dotNotationUtil.php | 16 | ||||
| -rw-r--r-- | app/Utils/feverUtil.php | 2 |
23 files changed, 94 insertions, 184 deletions
diff --git a/app/Controllers/apiController.php b/app/Controllers/apiController.php index 7c20b630b..585a7a9bb 100644 --- a/app/Controllers/apiController.php +++ b/app/Controllers/apiController.php @@ -9,9 +9,8 @@ class FreshRSS_api_Controller extends FreshRSS_ActionController { /** * Update the user API password. * Return an error message, or `false` if no error. - * @return false|string */ - public static function updatePassword(string $apiPasswordPlain) { + public static function updatePassword(string $apiPasswordPlain): string|false { $username = Minz_User::name(); if ($username == null) { return _t('feedback.api.password.failed'); diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php index 385bd1e2e..a9304376f 100644 --- a/app/Controllers/configureController.php +++ b/app/Controllers/configureController.php @@ -479,8 +479,6 @@ class FreshRSS_configure_Controller extends FreshRSS_ActionController { * - user category limit (default: 16384) * - user feed limit (default: 16384) * - user login duration for form auth (default: FreshRSS_Auth::DEFAULT_COOKIE_DURATION) - * - * The `force-email-validation` is ignored with PHP < 5.5 */ public function systemAction(): void { if (!FreshRSS_Auth::hasAccess('admin')) { diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index dbdf858a7..42639f5e1 100644 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -755,7 +755,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController { * @param int $nbNewEntries The number of top recent entries to process. * @return int|false The number of new labels added, or false in case of error. */ - private static function applyLabelActions(int $nbNewEntries) { + private static function applyLabelActions(int $nbNewEntries): int|false { $tagDAO = FreshRSS_Factory::createTagDao(); $labels = FreshRSS_Context::labels(); $labels = array_filter($labels, static function (FreshRSS_Tag $label) { diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 2dc25fa2f..c4f64337b 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -33,10 +33,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { FreshRSS_View::prependTitle(_t('sub.import_export.title') . ' · '); } - /** - * @return float|int|string - */ - private static function megabytes(string $size_str) { + private static function megabytes(string $size_str): float|int|string { switch (substr($size_str, -1)) { case 'M': case 'm': @@ -51,10 +48,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { return $size_str; } - /** - * @param string|int $mb - */ - private static function minimumMemory($mb): void { + private static function minimumMemory(int|string $mb): void { $mb = (int)$mb; $ini = self::megabytes(ini_get('memory_limit') ?: '0'); if ($ini < $mb) { @@ -240,11 +234,8 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { return 'unknown'; } - /** - * @return false|string - */ - private function ttrssXmlToJson(string $xml) { - $table = (array)simplexml_load_string($xml, null, LIBXML_NOBLANKS | LIBXML_NOCDATA); + private function ttrssXmlToJson(string $xml): string|false { + $table = (array)simplexml_load_string($xml, options: LIBXML_NOBLANKS | LIBXML_NOCDATA); $table['items'] = $table['article'] ?? []; unset($table['article']); for ($i = count($table['items']) - 1; $i >= 0; $i--) { diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php index f07ed338b..e5bf276cd 100644 --- a/app/Controllers/updateController.php +++ b/app/Controllers/updateController.php @@ -93,7 +93,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController { } /** @return string|true */ - public static function gitPull() { + public static function gitPull(): string|bool { Minz_Log::notice(_t('admin.update.viaGit')); $cwd = getcwd(); if ($cwd === false) { diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php index da770ade7..b101f0b3f 100644 --- a/app/Models/CategoryDAO.php +++ b/app/Models/CategoryDAO.php @@ -100,9 +100,8 @@ 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 */ - public function addCategory(array $valuesTmp) { + public function addCategory(array $valuesTmp): int|false { // TRIM() to provide a type hint as text // No tag of the same name $sql = <<<'SQL' @@ -136,8 +135,7 @@ SQL; } } - /** @return int|false */ - public function addCategoryObject(FreshRSS_Category $category) { + public function addCategoryObject(FreshRSS_Category $category): int|false { $cat = $this->searchByName($category->name()); if (!$cat) { $values = [ @@ -153,9 +151,8 @@ SQL; /** * @param array{'name':string,'kind':int,'attributes'?:array<string,mixed>|mixed|null} $valuesTmp - * @return int|false */ - public function updateCategory(int $id, array $valuesTmp) { + public function updateCategory(int $id, array $valuesTmp): int|false { // No tag of the same name $sql = <<<'SQL' UPDATE `_category` SET name=?, kind=?, attributes=? WHERE id=? @@ -187,8 +184,7 @@ SQL; } } - /** @return int|false */ - public function updateLastUpdate(int $id, bool $inError = false, int $mtime = 0) { + public function updateLastUpdate(int $id, bool $inError = false, int $mtime = 0): int|false { $sql = 'UPDATE `_category` SET `lastUpdate`=?, error=? WHERE id=?'; $values = [ $mtime <= 0 ? time() : $mtime, @@ -206,8 +202,7 @@ SQL; } } - /** @return int|false */ - public function deleteCategory(int $id) { + public function deleteCategory(int $id): int|false { if ($id <= self::DEFAULTCATEGORYID) { return false; } @@ -345,8 +340,7 @@ SQL; } } - /** @return int|bool */ - public function checkDefault() { + public function checkDefault(): int|bool { $def_cat = $this->searchById(self::DEFAULTCATEGORYID); if ($def_cat == null) { diff --git a/app/Models/Context.php b/app/Models/Context.php index 988eedc71..8634b5e71 100644 --- a/app/Models/Context.php +++ b/app/Models/Context.php @@ -274,7 +274,7 @@ final class FreshRSS_Context { * @phpstan-return ($asArray is true ? array{'a'|'c'|'f'|'i'|'s'|'t'|'T',bool|int} : string) * @return string|array{string,bool|int} */ - public static function currentGet(bool $asArray = false) { + public static function currentGet(bool $asArray = false): string|array { if (self::$current_get['all']) { return $asArray ? ['a', true] : 'a'; } elseif (self::$current_get['important']) { diff --git a/app/Models/Entry.php b/app/Models/Entry.php index f2701fb68..4b331419b 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -32,13 +32,10 @@ class FreshRSS_Entry extends Minz_Model { private array $tags = []; /** - * @param int|string $pubdate - * @param bool|int|null $is_read - * @param bool|int|null $is_favorite * @param string|array<string> $tags */ public function __construct(int $feedId = 0, string $guid = '', string $title = '', string $authors = '', string $content = '', - string $link = '', $pubdate = 0, $is_read = false, $is_favorite = false, $tags = '') { + string $link = '', int|string $pubdate = 0, bool|int|null $is_read = false, bool|int|null $is_favorite = false, $tags = '') { $this->_title($title); $this->_authors($authors); $this->_content($content); @@ -149,7 +146,7 @@ class FreshRSS_Entry extends Minz_Model { * @phpstan-return ($asString is true ? string : array<string>) * @return string|array<string> */ - public function authors(bool $asString = false) { + public function authors(bool $asString = false): string|array { if ($asString) { return $this->authors == null ? '' : ';' . implode('; ', $this->authors); } else { @@ -384,9 +381,8 @@ HTML; } /** * @phpstan-return ($raw is false ? string : int) - * @return string|int */ - public function date(bool $raw = false) { + public function date(bool $raw = false): int|string { if ($raw) { return $this->date; } @@ -402,9 +398,8 @@ HTML; /** * @phpstan-return ($raw is false ? string : ($microsecond is true ? string : int)) - * @return int|string */ - public function dateAdded(bool $raw = false, bool $microsecond = false) { + public function dateAdded(bool $raw = false, bool $microsecond = false): int|string { if ($raw) { if ($microsecond) { return $this->date_added; @@ -451,7 +446,7 @@ HTML; * @phpstan-return ($asString is true ? string : array<string>) * @return string|array<string> */ - public function tags(bool $asString = false) { + public function tags(bool $asString = false): array|string { if ($asString) { return $this->tags == null ? '' : '#' . implode(' #', $this->tags); } else { @@ -719,9 +714,7 @@ HTML; } } FreshRSS_Context::userConf()->applyFilterActions($this); - if ($feed->category() !== null) { - $feed->category()->applyFilterActions($this); - } + $feed->category()?->applyFilterActions($this); $feed->applyFilterActions($this); } diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php index a90b98a60..175df15c3 100644 --- a/app/Models/EntryDAO.php +++ b/app/Models/EntryDAO.php @@ -291,9 +291,8 @@ SQL; * there is an other way to do that. * * @param numeric-string|array<numeric-string> $ids - * @return int|false */ - public function markFavorite($ids, bool $is_favorite = true) { + public function markFavorite($ids, bool $is_favorite = true): int|false { if (!is_array($ids)) { $ids = [$ids]; } @@ -369,10 +368,9 @@ SQL; * Then the cache is updated. * * @param numeric-string|array<numeric-string> $ids - * @param bool $is_read * @return int|false affected rows */ - public function markRead($ids, bool $is_read = true) { + public function markRead(array|string $ids, bool $is_read = true): int|false { if (is_array($ids)) { //Many IDs at once if (count($ids) < 6) { //Speed heuristics $affected = 0; @@ -438,7 +436,7 @@ SQL; * @param numeric-string $idMax fail safe article ID * @return int|false affected rows */ - public function markReadEntries(string $idMax = '0', bool $onlyFavorites = false, ?int $priorityMin = null, ?int $prioritMax = null, + public function markReadEntries(string $idMax = '0', bool $onlyFavorites = false, ?int $priorityMin = null, ?int $priorityMax = null, ?FreshRSS_BooleanSearch $filters = null, int $state = 0, bool $is_read = true) { FreshRSS_UserDAO::touch(); if ($idMax == '0') { @@ -451,15 +449,15 @@ SQL; if ($onlyFavorites) { $sql .= ' AND is_favorite=1'; } - if ($priorityMin !== null || $prioritMax !== null) { + if ($priorityMin !== null || $priorityMax !== null) { $sql .= ' AND id_feed IN (SELECT f.id FROM `_feed` f WHERE 1=1'; if ($priorityMin !== null) { $sql .= ' AND f.priority >= ?'; $values[] = $priorityMin; } - if ($prioritMax !== null) { + if ($priorityMax !== null) { $sql .= ' AND f.priority < ?'; - $values[] = $prioritMax; + $values[] = $priorityMax; } $sql .= ')'; } @@ -490,7 +488,7 @@ SQL; * @param numeric-string $idMax fail safe article ID * @return int|false affected rows */ - public function markReadCat(int $id, string $idMax = '0', ?FreshRSS_BooleanSearch $filters = null, int $state = 0, bool $is_read = true) { + public function markReadCat(int $id, string $idMax = '0', ?FreshRSS_BooleanSearch $filters = null, int $state = 0, bool $is_read = true): int|false { FreshRSS_UserDAO::touch(); if ($idMax == '0') { $idMax = time() . '000000'; @@ -531,7 +529,7 @@ SQL; * @param numeric-string $idMax fail safe article ID * @return int|false affected rows */ - public function markReadFeed(int $id_feed, string $idMax = '0', ?FreshRSS_BooleanSearch $filters = null, int $state = 0, bool $is_read = true) { + public function markReadFeed(int $id_feed, string $idMax = '0', ?FreshRSS_BooleanSearch $filters = null, int $state = 0, bool $is_read = true): int|false { FreshRSS_UserDAO::touch(); if ($idMax == '0') { $idMax = time() . '000000'; @@ -623,9 +621,8 @@ SQL; /** * Remember to call updateCachedValues($id_feed) or updateCachedValues() just after. * @param array<string,bool|int|string> $options - * @return int|false */ - public function cleanOldEntries(int $id_feed, array $options = []) { + public function cleanOldEntries(int $id_feed, array $options = []): int|false { $sql = 'DELETE FROM `_entry` WHERE id_feed = :id_feed1'; //No alias for MySQL / MariaDB $params = []; $params[':id_feed1'] = $id_feed; @@ -1121,12 +1118,11 @@ SQL; * @phpstan-param 'a'|'A'|'s'|'S'|'i'|'c'|'f'|'t'|'T'|'ST' $type * @param 'ASC'|'DESC' $order * @param int $id category/feed/tag ID - * @return PDOStatement|false * @throws FreshRSS_EntriesGetter_Exception */ private function listWhereRaw(string $type = 'a', int $id = 0, int $state = FreshRSS_Entry::STATE_ALL, string $order = 'DESC', int $limit = 1, int $offset = 0, string $firstId = '', ?FreshRSS_BooleanSearch $filters = null, - int $date_min = 0) { + int $date_min = 0): PDOStatement|false { [$values, $sql] = $this->sqlListWhere($type, $id, $state, $order, $limit, $offset, $firstId, $filters, $date_min); if ($order !== 'DESC' && $order !== 'ASC') { @@ -1244,7 +1240,7 @@ SQL; * @param array<string> $guids * @return array<string>|false */ - public function listHashForFeedGuids(int $id_feed, array $guids) { + public function listHashForFeedGuids(int $id_feed, array $guids): array|false { $result = []; if (count($guids) < 1) { return $result; @@ -1283,7 +1279,7 @@ SQL; * @param array<string> $guids * @return int|false The number of affected entries, or false if error */ - public function updateLastSeen(int $id_feed, array $guids, int $mtime = 0) { + public function updateLastSeen(int $id_feed, array $guids, int $mtime = 0): int|false { if (count($guids) < 1) { return 0; } elseif (count($guids) > FreshRSS_DatabaseDAO::MAX_VARIABLE_NUMBER) { @@ -1321,7 +1317,7 @@ SQL; * To be performed just before {@see FreshRSS_FeedDAO::updateLastUpdate()} * @return int|false The number of affected entries, or false in case of error */ - public function updateLastSeenUnchanged(int $id_feed, int $mtime = 0) { + public function updateLastSeenUnchanged(int $id_feed, int $mtime = 0): int|false { $sql = <<<'SQL' UPDATE `_entry` SET `lastSeen` = :mtime WHERE id_feed = :id_feed1 AND `lastSeen` = ( diff --git a/app/Models/EntryDAOSQLite.php b/app/Models/EntryDAOSQLite.php index d6364fec9..9c2b37623 100644 --- a/app/Models/EntryDAOSQLite.php +++ b/app/Models/EntryDAOSQLite.php @@ -77,12 +77,11 @@ SQL; * Toggle the read marker on one or more article. * Then the cache is updated. * - * @param string|array<string> $ids - * @param bool $is_read + * @param numeric-string|array<numeric-string> $ids * @return int|false affected rows */ #[\Override] - public function markRead($ids, bool $is_read = true) { + public function markRead(array|string $ids, bool $is_read = true): int|false { if (is_array($ids)) { //Many IDs at once (used by API) //if (true) { //Speed heuristics //TODO: Not implemented yet for SQLite (so always call IDs one by one) $affected = 0; @@ -128,7 +127,7 @@ SQL; * @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) { + public function markReadTag($id = 0, string $idMax = '0', ?FreshRSS_BooleanSearch $filters = null, int $state = 0, bool $is_read = true): int|false { FreshRSS_UserDAO::touch(); if ($idMax == 0) { $idMax = time() . '000000'; diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 36cc58cfd..6e468e33f 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -116,10 +116,7 @@ class FreshRSS_Feed extends Minz_Model { } public function categoryId(): int { - if ($this->category !== null) { - return $this->category->id() ?: $this->categoryId; - } - return $this->categoryId; + return $this->category?->id() ?: $this->categoryId; } /** @@ -155,7 +152,7 @@ class FreshRSS_Feed extends Minz_Model { * @phpstan-return ($raw is true ? string : array{'username':string,'password':string}) * @return array{'username':string,'password':string}|string */ - public function httpAuth(bool $raw = true) { + public function httpAuth(bool $raw = true): array|string { if ($raw) { return $this->httpAuth; } else { @@ -816,7 +813,7 @@ class FreshRSS_Feed extends Minz_Model { /** * @return int|null The max number of unread articles to keep, or null if disabled. */ - public function keepMaxUnread() { + public function keepMaxUnread(): ?int { $keepMaxUnread = $this->attributeInt('keep_max_n_unread'); if ($keepMaxUnread === null) { $keepMaxUnread = FreshRSS_Context::userConf()->mark_when['max_n_unread']; @@ -827,7 +824,7 @@ class FreshRSS_Feed extends Minz_Model { /** * @return int|false The number of articles marked as read, of false if error */ - public function markAsReadMaxUnread() { + public function markAsReadMaxUnread(): int|false { $keepMaxUnread = $this->keepMaxUnread(); if ($keepMaxUnread === null) { return false; @@ -842,7 +839,7 @@ class FreshRSS_Feed extends Minz_Model { * Remember to call `updateCachedValues($id_feed)` or `updateCachedValues()` just after. * @return int|false the number of lines affected, or false if not applicable */ - public function markAsReadUponGone(bool $upstreamIsEmpty, int $minLastSeen = 0) { + public function markAsReadUponGone(bool $upstreamIsEmpty, int $minLastSeen = 0): int|false { $readUponGone = $this->attributeBoolean('read_upon_gone'); if ($readUponGone === null) { $readUponGone = FreshRSS_Context::userConf()->mark_when['gone']; @@ -868,9 +865,8 @@ class FreshRSS_Feed extends Minz_Model { /** * Remember to call `updateCachedValues($id_feed)` or `updateCachedValues()` just after - * @return int|false */ - public function cleanOldEntries() { + public function cleanOldEntries(): int|false { /** @var array<string,bool|int|string>|null $archiving */ $archiving = $this->attributeArray('archiving'); if ($archiving === null) { @@ -926,7 +922,7 @@ class FreshRSS_Feed extends Minz_Model { } /** @return int|false */ - public function cacheModifiedTime() { + public function cacheModifiedTime(): int|false { $filename = $this->cacheFilename(); clearstatcache(true, $filename); return @filemtime($filename); @@ -977,10 +973,7 @@ class FreshRSS_Feed extends Minz_Model { return false; } - /** - * @return string|false - */ - public function pubSubHubbubPrepare() { + public function pubSubHubbubPrepare(): string|false { $key = ''; if (Minz_Request::serverIsPublic(FreshRSS_Context::systemConf()->base_url) && $this->hubUrl && $this->selfUrl && @is_dir(PSHB_PATH)) { diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index 11eef4e90..96a8fc3c5 100644 --- a/app/Models/FeedDAO.php +++ b/app/Models/FeedDAO.php @@ -36,9 +36,8 @@ 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 */ - public function addFeed(array $valuesTmp) { + public function addFeed(array $valuesTmp): int|false { $sql = 'INSERT INTO `_feed` (url, kind, category, name, website, description, `lastUpdate`, priority, `pathEntries`, `httpAuth`, error, ttl, attributes) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; $stm = $this->pdo->prepare($sql); @@ -81,8 +80,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { } } - /** @return int|false */ - public function addFeedObject(FreshRSS_Feed $feed) { + public function addFeedObject(FreshRSS_Feed $feed): int|false { // Add feed only if we don’t find it in DB $feed_search = $this->searchByUrl($feed->url()); if (!$feed_search) { @@ -141,9 +139,8 @@ 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,'ttl'?:int,'attributes'?:string|array<string,mixed>} $valuesTmp $valuesTmp - * @return int|false */ - public function updateFeed(int $id, array $valuesTmp) { + public function updateFeed(int $id, array $valuesTmp): int|false { $values = []; $originalValues = $valuesTmp; if (isset($valuesTmp['name'])) { @@ -191,9 +188,8 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { /** * @param non-empty-string $key * @param string|array<mixed>|bool|int|null $value - * @return int|false */ - public function updateFeedAttribute(FreshRSS_Feed $feed, string $key, $value) { + public function updateFeedAttribute(FreshRSS_Feed $feed, string $key, $value): int|false { $feed->_attribute($key, $value); return $this->updateFeed( $feed->id(), @@ -202,10 +198,9 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { } /** - * @return int|false * @see updateCachedValues() */ - public function updateLastUpdate(int $id, bool $inError = false, int $mtime = 0) { + public function updateLastUpdate(int $id, bool $inError = false, int $mtime = 0): int|false { $sql = 'UPDATE `_feed` SET `lastUpdate`=?, error=? WHERE id=?'; $values = [ $mtime <= 0 ? time() : $mtime, @@ -223,14 +218,12 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { } } - /** @return int|false */ - public function mute(int $id, bool $value = true) { + public function mute(int $id, bool $value = true): int|false { $sql = 'UPDATE `_feed` SET ttl=' . ($value ? '-' : '') . 'ABS(ttl) WHERE id=' . intval($id); return $this->pdo->exec($sql); } - /** @return int|false */ - public function changeCategory(int $idOldCat, int $idNewCat) { + public function changeCategory(int $idOldCat, int $idNewCat): int|false { $catDAO = FreshRSS_Factory::createCategoryDao(); $newCat = $catDAO->searchById($idNewCat); if ($newCat === null) { @@ -257,8 +250,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { } } - /** @return int|false */ - public function deleteFeed(int $id) { + public function deleteFeed(int $id): int|false { $sql = 'DELETE FROM `_feed` WHERE id=?'; $stm = $this->pdo->prepare($sql); @@ -275,9 +267,8 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo { /** * @param bool|null $muted to include only muted feeds - * @return int|false */ - public function deleteFeedByCategory(int $id, ?bool $muted = null) { + public function deleteFeedByCategory(int $id, ?bool $muted = null): int|false { $sql = 'DELETE FROM `_feed` WHERE category=?'; if ($muted) { $sql .= ' AND ttl < 0'; @@ -454,9 +445,8 @@ SQL; /** * Update cached values for selected feeds, or all feeds if no feed ID is provided. - * @return int|false */ - public function updateCachedValues(int ...$feedIds) { + public function updateCachedValues(int ...$feedIds): int|false { //2 sub-requests with FOREIGN KEY(e.id_feed), INDEX(e.is_read) faster than 1 request with GROUP BY or CASE $sql = <<<SQL UPDATE `_feed` @@ -480,7 +470,7 @@ SQL; * Remember to call updateCachedValues() after calling this function * @return int|false number of lines affected or false in case of error */ - public function markAsReadMaxUnread(int $id, int $n) { + public function markAsReadMaxUnread(int $id, int $n): int|false { //Double SELECT for MySQL workaround ERROR 1093 (HY000) $sql = <<<'SQL' UPDATE `_entry` SET is_read=1 @@ -509,7 +499,7 @@ SQL; * Remember to call updateCachedValues() after calling this function * @return int|false number of lines affected or false in case of error */ - public function markAsReadNotSeen(int $id, int $minLastSeen) { + public function markAsReadNotSeen(int $id, int $minLastSeen): int|false { $sql = <<<'SQL' UPDATE `_entry` SET is_read=1 WHERE id_feed=:id_feed AND is_read=0 AND (`lastSeen` + 10 < :min_last_seen) @@ -527,10 +517,7 @@ SQL; } } - /** - * @return int|false - */ - public function truncate(int $id) { + public function truncate(int $id): int|false { $sql = 'DELETE FROM `_entry` WHERE id_feed=:id'; $stm = $this->pdo->prepare($sql); $this->pdo->beginTransaction(); diff --git a/app/Models/FormAuth.php b/app/Models/FormAuth.php index a8b4dab8a..5bd6d97bc 100644 --- a/app/Models/FormAuth.php +++ b/app/Models/FormAuth.php @@ -38,8 +38,7 @@ class FreshRSS_FormAuth { return []; } - /** @return string|false */ - private static function renewCookie(string $token) { + private static function renewCookie(string $token): string|false { $token_file = DATA_PATH . '/tokens/' . $token . '.txt'; if (touch($token_file)) { $limits = FreshRSS_Context::systemConf()->limits; @@ -51,8 +50,7 @@ class FreshRSS_FormAuth { return false; } - /** @return string|false */ - public static function makeCookie(string $username, string $password_hash) { + public static function makeCookie(string $username, string $password_hash): string|false { do { $token = sha1(FreshRSS_Context::systemConf()->salt . $username . uniqid('' . mt_rand(), true)); $token_file = DATA_PATH . '/tokens/' . $token . '.txt'; diff --git a/app/Models/Search.php b/app/Models/Search.php index 31b3d8d5a..7eaf741c3 100644 --- a/app/Models/Search.php +++ b/app/Models/Search.php @@ -135,11 +135,11 @@ class FreshRSS_Search { } /** @return array<int>|'*'|null */ - public function getLabelIds() { + public function getLabelIds(): array|string|null { return $this->label_ids; } /** @return array<int>|'*'|null */ - public function getNotLabelIds() { + public function getNotLabelIds(): array|string|null { return $this->not_label_ids; } /** @return array<string>|null */ @@ -242,7 +242,7 @@ class FreshRSS_Search { * @param array<string>|string $value * @return ($value is array ? array<string> : string) */ - private static function decodeSpaces($value) { + private static function decodeSpaces($value): array|string { if (is_array($value)) { for ($i = count($value) - 1; $i >= 0; $i--) { $value[$i] = self::decodeSpaces($value[$i]); diff --git a/app/Models/Share.php b/app/Models/Share.php index 9c8f2084e..2df9dd4d9 100644 --- a/app/Models/Share.php +++ b/app/Models/Share.php @@ -106,9 +106,7 @@ class FreshRSS_Share { * decentralized ones. * @param string $help_url is an optional url to give help on this option. * @param 'GET'|'POST' $method defines the sharing method (GET or POST) - * @param string|null $field * @param 'button'|null $HTMLtag - * @param bool $isDeprecated */ private function __construct(string $type, string $url_transform, array $transforms, string $form_type, string $help_url, string $method, ?string $field, ?string $HTMLtag, bool $isDeprecated = false) { diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.php index 6331e24f2..c9753cf2c 100644 --- a/app/Models/StatsDAO.php +++ b/app/Models/StatsDAO.php @@ -31,7 +31,7 @@ class FreshRSS_StatsDAO extends Minz_ModelPdo { * * @return array{'total':int,'count_unreads':int,'count_reads':int,'count_favorites':int}|false */ - public function calculateEntryRepartitionPerFeed(?int $feed = null, bool $only_main = false) { + public function calculateEntryRepartitionPerFeed(?int $feed = null, bool $only_main = false): array|false { $filter = ''; if ($only_main) { $filter .= 'AND f.priority = 10'; diff --git a/app/Models/Tag.php b/app/Models/Tag.php index 0ed7c462c..9a3baffcd 100644 --- a/app/Models/Tag.php +++ b/app/Models/Tag.php @@ -17,10 +17,7 @@ class FreshRSS_Tag extends Minz_Model { return $this->id; } - /** - * @param int|string $value - */ - public function _id($value): void { + public function _id(int|string $value): void { $this->id = (int)$value; } @@ -40,10 +37,7 @@ class FreshRSS_Tag extends Minz_Model { return $this->nbEntries; } - /** - * @param string|int $value - */ - public function _nbEntries($value): void { + public function _nbEntries(int|string $value): void { $this->nbEntries = (int)$value; } @@ -55,10 +49,7 @@ class FreshRSS_Tag extends Minz_Model { return $this->nbUnread; } - /** - * @param string|int $value - */ - public function _nbUnread($value): void { + public function _nbUnread(int|string $value): void { $this->nbUnread = (int)$value; } } diff --git a/app/Models/TagDAO.php b/app/Models/TagDAO.php index 1feba263e..920a09c2c 100644 --- a/app/Models/TagDAO.php +++ b/app/Models/TagDAO.php @@ -9,9 +9,8 @@ class FreshRSS_TagDAO extends Minz_ModelPdo { /** * @param array{'id'?:int,'name':string,'attributes'?:array<string,mixed>} $valuesTmp - * @return int|false */ - public function addTag(array $valuesTmp) { + public function addTag(array $valuesTmp): int|false { // TRIM() gives a text type hint to PostgreSQL // No category of the same name $sql = <<<'SQL' @@ -41,8 +40,7 @@ SQL; } } - /** @return int|false */ - public function addTagObject(FreshRSS_Tag $tag) { + public function addTagObject(FreshRSS_Tag $tag): int|false { $tag0 = $this->searchByName($tag->name()); if (!$tag0) { $values = [ @@ -54,8 +52,7 @@ SQL; return $tag->id(); } - /** @return int|false */ - public function updateTagName(int $id, string $name) { + public function updateTagName(int $id, string $name): int|false { // No category of the same name $sql = <<<'SQL' UPDATE `_tag` SET name = :name1 WHERE id = :id @@ -79,9 +76,8 @@ SQL; /** * @param array<string,mixed> $attributes - * @return int|false */ - public function updateTagAttributes(int $id, array $attributes) { + public function updateTagAttributes(int $id, array $attributes): int|false { $sql = 'UPDATE `_tag` SET attributes=:attributes WHERE id=:id'; $stm = $this->pdo->prepare($sql); if ($stm !== false && @@ -97,18 +93,13 @@ SQL; /** * @param non-empty-string $key - * @param mixed $value - * @return int|false */ - public function updateTagAttribute(FreshRSS_Tag $tag, string $key, $value) { + public function updateTagAttribute(FreshRSS_Tag $tag, string $key, mixed $value): int|false { $tag->_attribute($key, $value); return $this->updateTagAttributes($tag->id(), $tag->attributes()); } - /** - * @return int|false - */ - public function deleteTag(int $id) { + public function deleteTag(int $id): int|false { if ($id <= 0) { return false; } @@ -155,8 +146,7 @@ SQL; } } - /** @return int|false */ - public function updateEntryTag(int $oldTagId, int $newTagId) { + public function updateEntryTag(int $oldTagId, int $newTagId): int|false { $sql = <<<'SQL' DELETE FROM `_entrytag` WHERE EXISTS ( SELECT 1 FROM `_entrytag` AS e @@ -194,7 +184,7 @@ SQL; } /** @return array<int,FreshRSS_Tag>|false */ - public function listTags(bool $precounts = false) { + public function listTags(bool $precounts = false): array|false { if ($precounts) { $sql = <<<'SQL' SELECT t.id, t.name, count(e.id) AS unreads @@ -304,7 +294,7 @@ SQL; * @param array<array{id_tag:int,id_entry:string}> $addLabels Labels to insert as batch * @return int|false Number of new entries or false in case of error */ - public function tagEntries(array $addLabels) { + public function tagEntries(array $addLabels): int|false { $hasValues = false; $sql = 'INSERT ' . $this->sqlIgnore() . ' INTO `_entrytag`(id_tag, id_entry) VALUES '; foreach ($addLabels as $addLabel) { @@ -332,7 +322,7 @@ SQL; /** * @return array<int,array{'id':int,'name':string,'id_entry':string,'checked':bool}>|false */ - public function getTagsForEntry(string $id_entry) { + public function getTagsForEntry(string $id_entry): array|false { $sql = <<<'SQL' SELECT t.id, t.name, et.id_entry IS NOT NULL as checked FROM `_tag` t @@ -360,7 +350,7 @@ SQL; * @param array<FreshRSS_Entry|numeric-string|array<string,string>> $entries * @return array<array{'id_entry':string,'id_tag':int,'name':string}>|false */ - public function getTagsForEntries(array $entries) { + public function getTagsForEntries(array $entries): array|false { $sql = <<<'SQL' SELECT et.id_entry, et.id_tag, t.name FROM `_tag` t diff --git a/app/Models/Themes.php b/app/Models/Themes.php index 04ce0a36d..055db42e5 100644 --- a/app/Models/Themes.php +++ b/app/Models/Themes.php @@ -31,7 +31,7 @@ class FreshRSS_Themes extends Minz_Model { /** * @return false|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_infos(string $theme_id) { + public static function get_infos(string $theme_id): array|false { $theme_dir = PUBLIC_PATH . self::$themesUrl . $theme_id; if (is_dir($theme_dir)) { $json_filename = $theme_dir . '/metadata.json'; @@ -58,7 +58,7 @@ class FreshRSS_Themes extends Minz_Model { /** * @return false|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 load(string $theme_id) { + public static function load(string $theme_id): array|false { $infos = self::get_infos($theme_id); if (!$infos) { if ($theme_id !== self::$defaultTheme) { //Fall-back to default theme diff --git a/app/Services/ExportService.php b/app/Services/ExportService.php index 91c8c91e3..ba4042d21 100644 --- a/app/Services/ExportService.php +++ b/app/Services/ExportService.php @@ -16,13 +16,13 @@ class FreshRSS_Export_Service { private FreshRSS_TagDAO $tag_dao; - public const FRSS_NAMESPACE = 'https://freshrss.org/opml'; - public const TYPE_HTML_XPATH = 'HTML+XPath'; - public const TYPE_XML_XPATH = 'XML+XPath'; - public const TYPE_RSS_ATOM = 'rss'; - public const TYPE_JSON_DOTPATH = 'JSON+DotPath'; // Legacy 1.24.0-dev - public const TYPE_JSON_DOTNOTATION = 'JSON+DotNotation'; - public const TYPE_JSONFEED = 'JSONFeed'; + final public const FRSS_NAMESPACE = 'https://freshrss.org/opml'; + final public const TYPE_HTML_XPATH = 'HTML+XPath'; + final public const TYPE_XML_XPATH = 'XML+XPath'; + final public const TYPE_RSS_ATOM = 'rss'; + final public const TYPE_JSON_DOTPATH = 'JSON+DotPath'; // Legacy 1.24.0-dev + final public const TYPE_JSON_DOTNOTATION = 'JSON+DotNotation'; + final public const TYPE_JSONFEED = 'JSONFeed'; /** * Initialize the service for the given user. @@ -87,8 +87,6 @@ class FreshRSS_Export_Service { /** * Generate the entries file content for the given feed. - * @param int $feed_id - * @param int $max_number_entries * @return array{0:string,1:string}|null First item is the filename, second item is the content. * It also can return null if the feed doesn’t exist. */ @@ -124,7 +122,6 @@ class FreshRSS_Export_Service { /** * Generate the entries file content for all the feeds. - * @param int $max_number_entries * @return array<string,string> Keys are filenames and values are contents. */ public function generateAllFeedEntries(int $max_number_entries): array { diff --git a/app/Services/ImportService.php b/app/Services/ImportService.php index 11da49217..8060e4d51 100644 --- a/app/Services/ImportService.php +++ b/app/Services/ImportService.php @@ -362,10 +362,8 @@ class FreshRSS_Import_Service { * This method is applied to a list of outlines. It merges the different * list of feeds from several outlines into one array. * - * @param array<array<mixed>> $outlines - * The outlines from which to extract the outlines. - * @param string $parent_category_name - * The name of the parent category of the current outlines. + * @param array<array<mixed>> $outlines The outlines from which to extract the outlines. + * @param string $parent_category_name The name of the parent category of the current outlines. * @return array{0:array<string,array<string,string>>,1:array<string,array<array<string,string>>>} */ private function loadFromOutlines(array $outlines, string $parent_category_name): array { @@ -405,10 +403,8 @@ class FreshRSS_Import_Service { * exists), it will add the outline to an array accessible by its category * name. * - * @param array<mixed> $outline - * The outline from which to extract the categories and feeds outlines. - * @param string $parent_category_name - * The name of the parent category of the current outline. + * @param array<mixed> $outline The outline from which to extract the categories and feeds outlines. + * @param string $parent_category_name The name of the parent category of the current outline. * * @return array{0:array<string,array<string,string>>,1:array<array<string,array<string,string>>>} */ diff --git a/app/Utils/dotNotationUtil.php b/app/Utils/dotNotationUtil.php index 9c44e5312..73addbe74 100644 --- a/app/Utils/dotNotationUtil.php +++ b/app/Utils/dotNotationUtil.php @@ -12,11 +12,8 @@ final class FreshRSS_dotNotation_Util * https://github.com/laravel/framework/blob/10.x/src/Illuminate/Collections/Arr.php#L302-L337 * * @param \ArrayAccess<string,mixed>|array<string,mixed>|mixed $array - * @param string|null $key - * @param mixed $default - * @return mixed */ - public static function get($array, ?string $key, mixed $default = null) { + public static function get($array, ?string $key, mixed $default = null): mixed { if (!static::accessible($array)) { return static::value($default); } @@ -51,7 +48,6 @@ final class FreshRSS_dotNotation_Util * Get a string from an array using "dot" notation. * * @param \ArrayAccess<string,mixed>|array<string,mixed>|mixed $array - * @param string|null $key */ public static function getString($array, ?string $key): ?string { $result = self::get($array, $key, null); @@ -60,11 +56,8 @@ final class FreshRSS_dotNotation_Util /** * Determine whether the given value is array accessible. - * - * @param mixed $value - * @return bool */ - private static function accessible($value): bool { + private static function accessible(mixed $value): bool { return is_array($value) || $value instanceof \ArrayAccess; } @@ -72,8 +65,6 @@ final class FreshRSS_dotNotation_Util * Determine if the given key exists in the provided array. * * @param \ArrayAccess<string,mixed>|array<string,mixed>|mixed $array - * @param string $key - * @return bool */ private static function exists($array, string $key): bool { if ($array instanceof \ArrayAccess) { @@ -85,8 +76,7 @@ final class FreshRSS_dotNotation_Util return false; } - /** @param mixed $value */ - private static function value($value): mixed { + private static function value(mixed $value): mixed { return $value instanceof Closure ? $value() : $value; } diff --git a/app/Utils/feverUtil.php b/app/Utils/feverUtil.php index 571c2bc00..8b06568dd 100644 --- a/app/Utils/feverUtil.php +++ b/app/Utils/feverUtil.php @@ -38,7 +38,7 @@ class FreshRSS_fever_Util { * @return string|false the Fever key, or false if the update failed * @throws FreshRSS_Context_Exception */ - public static function updateKey(string $username, string $passwordPlain) { + public static function updateKey(string $username, string $passwordPlain): string|false { if (!self::checkFeverPath()) { return false; } |
