diff options
| author | 2024-11-28 17:11:04 +0100 | |
|---|---|---|
| committer | 2024-11-28 17:11:04 +0100 | |
| commit | 15745d42b779ad14efde2932ab116f45eee39246 (patch) | |
| tree | 2528a36184d8152d4f2d90dc73df680f84bbe1d1 /app | |
| parent | 604b186638276203c8495a3ee86da0cc240ab4d0 (diff) | |
Upgrade code to php 8.1 (#6748)
* revert
Fix code indentation
Fix code
Upgrade code to php 8.1
* fix remarques
* code review
* code review
* code review
* Apply suggestions from code review
* code review
* Fixes
* Many remainging updates of array syntax
* Lost case 'reading-list'
* Uneeded PHPDoc
---------
Co-authored-by: Luc Sanchez <l.sanchez-prestataire@alptis.fr>
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Diffstat (limited to 'app')
47 files changed, 232 insertions, 347 deletions
diff --git a/app/Controllers/authController.php b/app/Controllers/authController.php index ed021505d..700501371 100644 --- a/app/Controllers/authController.php +++ b/app/Controllers/authController.php @@ -72,27 +72,18 @@ class FreshRSS_auth_Controller extends FreshRSS_ActionController { $auth_type = FreshRSS_Context::systemConf()->auth_type; FreshRSS_Context::initUser(Minz_User::INTERNAL_USER, false); - switch ($auth_type) { - case 'form': - Minz_Request::forward(['c' => 'auth', 'a' => 'formLogin']); - break; - case 'http_auth': - Minz_Error::error(403, [ + match ($auth_type) { + 'form' => Minz_Request::forward(['c' => 'auth', 'a' => 'formLogin']), + 'http_auth' => Minz_Error::error(403, [ 'error' => [ _t('feedback.access.denied'), ' [HTTP Remote-User=' . htmlspecialchars(httpAuthUser(false), ENT_NOQUOTES, 'UTF-8') . ' ; Remote IP address=' . connectionRemoteAddress() . ']' ] - ], false); - break; - case 'none': - // It should not happen! - Minz_Error::error(404); - break; - default: - // TODO load plugin instead - Minz_Error::error(404); - } + ], false), + 'none' => Minz_Error::error(404), // It should not happen! + default => Minz_Error::error(404), // TODO load plugin instead + }; } /** diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php index ebca7318d..b7cd01242 100644 --- a/app/Controllers/configureController.php +++ b/app/Controllers/configureController.php @@ -515,7 +515,7 @@ class FreshRSS_configure_Controller extends FreshRSS_ActionController { FreshRSS_Context::userConf()->save(); invalidateHttpCache(); - Minz_Request::good(_t('feedback.conf.updated'), array('c' => 'configure', 'a' => 'privacy')); + Minz_Request::good(_t('feedback.conf.updated'), ['c' => 'configure', 'a' => 'privacy']); } FreshRSS_View::prependTitle(_t('conf.privacy') . ' · '); diff --git a/app/Controllers/errorController.php b/app/Controllers/errorController.php index 59e910bac..81ce8768d 100644 --- a/app/Controllers/errorController.php +++ b/app/Controllers/errorController.php @@ -12,7 +12,7 @@ class FreshRSS_error_Controller extends FreshRSS_ActionController { * * Parameters are passed by Minz_Session to have a proper url: * - error_code (default: 404) - * - error_logs (default: array()) + * - error_logs (default: []) */ public function indexAction(): void { $code_int = Minz_Session::paramInt('error_code') ?: 404; @@ -60,7 +60,7 @@ class FreshRSS_error_Controller extends FreshRSS_ActionController { break; } - $error_message = trim(implode($error_logs)); + $error_message = trim(implode('', $error_logs)); if ($error_message !== '') { $this->view->errorMessage = $error_message; } diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 89f3d65b1..60ee6d579 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -343,7 +343,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController { // We try to get more information about the feed. $this->view->feed->load(true); $this->view->load_ok = true; - } catch (Exception $e) { + } catch (Exception) { $this->view->load_ok = false; } @@ -793,9 +793,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController { 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) { - return !empty($label->filtersAction('label')); - }); + $labels = array_filter($labels, static fn(FreshRSS_Tag $label) => !empty($label->filtersAction('label'))); if (count($labels) <= 0) { return 0; } @@ -1203,7 +1201,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController { $this->view->selectorSuccess = false; $this->view->htmlContent = $entry->content(false); } - } catch (Exception $e) { + } catch (Exception) { $this->view->fatalError = _t('feedback.sub.feed.selector_preview.http_error'); } } diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 53617ced7..afb1cbfec 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -35,18 +35,12 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { } private static function megabytes(string $size_str): float|int|string { - switch (substr($size_str, -1)) { - case 'M': - case 'm': - return (int)$size_str; - case 'K': - case 'k': - return (int)$size_str / 1024; - case 'G': - case 'g': - return (int)$size_str * 1024; - } - return $size_str; + return match (substr($size_str, -1)) { + 'M', 'm' => (int)$size_str, + 'K', 'k' => (int)$size_str / 1024, + 'G', 'g' => (int)$size_str * 1024, + default => $size_str, + }; } private static function minimumMemory(int|string $mb): void { @@ -190,7 +184,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { $error = false; try { $error = !$this->importFile($file['name'], $file['tmp_name']); - } catch (FreshRSS_ZipMissing_Exception $zme) { + } catch (FreshRSS_ZipMissing_Exception) { Minz_Request::bad( _t('feedback.import_export.no_zip_extension'), ['c' => 'importExport', 'a' => 'index'] @@ -215,17 +209,17 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { * That could be improved but should be enough for what we have to do. */ private static function guessFileType(string $filename): string { - if (substr_compare($filename, '.zip', -4) === 0) { + if (str_ends_with($filename, '.zip')) { return 'zip'; } elseif (stripos($filename, 'opml') !== false) { return 'opml'; - } elseif (substr_compare($filename, '.json', -5) === 0) { - if (strpos($filename, 'starred') !== false) { + } elseif (str_ends_with($filename, '.json')) { + if (str_contains($filename, 'starred')) { return 'json_starred'; } else { return 'json_feed'; } - } elseif (substr_compare($filename, '.xml', -4) === 0) { + } elseif (str_ends_with($filename, '.xml')) { if (preg_match('/Tiny|tt-?rss/i', $filename)) { return 'ttrss_starred'; } else { @@ -258,7 +252,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { $labels_cache = json_decode($item['label_cache'], true); if (is_array($labels_cache)) { foreach ($labels_cache as $label_cache) { - if (!empty($label_cache[1])) { + if (!empty($label_cache[1]) && is_string($label_cache[1])) { $item['categories'][] = 'user/-/label/' . trim($label_cache[1]); } } @@ -322,7 +316,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { } if (!empty($item['origin']['feedUrl'])) { $feedUrl = $item['origin']['feedUrl']; - } elseif (!empty($item['origin']['streamId']) && strpos($item['origin']['streamId'], 'feed/') === 0) { + } elseif (!empty($item['origin']['streamId']) && str_starts_with($item['origin']['streamId'], 'feed/')) { $feedUrl = substr($item['origin']['streamId'], 5); //Google Reader $item['origin']['feedUrl'] = $feedUrl; } elseif (!empty($item['origin']['htmlUrl'])) { @@ -588,7 +582,7 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { * - export_opml (default: false) * - export_starred (default: false) * - export_labelled (default: false) - * - export_feeds (default: array()) a list of feed ids + * - export_feeds (default: []) a list of feed ids */ public function exportAction(): void { if (!Minz_Request::isPost()) { @@ -683,17 +677,12 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { */ private static function filenameToContentType(string $filename): string { $filetype = self::guessFileType($filename); - switch ($filetype) { - case 'zip': - return 'application/zip'; - case 'opml': - return 'application/xml; charset=utf-8'; - case 'json_starred': - case 'json_feed': - return 'application/json; charset=utf-8'; - default: - return 'application/octet-stream'; - } + return match ($filetype) { + 'zip' => 'application/zip', + 'opml' => 'application/xml; charset=utf-8', + 'json_starred', 'json_feed' => 'application/json; charset=utf-8', + default => 'application/octet-stream', + }; } private const REGEX_SQLITE_FILENAME = '/^(?![.-])[0-9a-zA-Z_.@ #&()~\-]{1,128}\.sqlite$/'; diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index 2ee72b7b7..a977386a3 100644 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -117,7 +117,7 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController { try { FreshRSS_Context::updateUsingRequest(true); - } catch (FreshRSS_Context_Exception $e) { + } catch (FreshRSS_Context_Exception) { Minz_Error::error(404); } @@ -194,7 +194,7 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController { try { FreshRSS_Context::updateUsingRequest(false); - } catch (FreshRSS_Context_Exception $e) { + } catch (FreshRSS_Context_Exception) { Minz_Error::error(404); } diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php index e5bf276cd..c7623d0a4 100644 --- a/app/Controllers/updateController.php +++ b/app/Controllers/updateController.php @@ -89,7 +89,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController { chdir($cwd); $line = implode('; ', $output); return $line == '' || - strpos($line, '[behind') !== false || strpos($line, '[ahead') !== false || strpos($line, '[gone') !== false; + str_contains($line, '[behind') || str_contains($line, '[ahead') || str_contains($line, '[gone'); } /** @return string|true */ @@ -169,8 +169,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController { } private function is_release_channel_stable(string $currentVersion): bool { - return strpos($currentVersion, 'dev') === false && - strpos($currentVersion, 'edge') === false; + return !str_contains($currentVersion, 'dev') && !str_contains($currentVersion, 'edge'); } /* Check installation if there is a newer version. @@ -239,7 +238,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController { $res_array = explode("\n", (string)$result, 2); $status = $res_array[0]; - if (strpos($status, 'UPDATE') !== 0) { + if (!str_starts_with($status, 'UPDATE')) { $this->view->message = [ 'status' => 'latest', 'body' => _t('feedback.update.none'), diff --git a/app/Exceptions/AlreadySubscribedException.php b/app/Exceptions/AlreadySubscribedException.php index 8e2eaa13a..977798ae4 100644 --- a/app/Exceptions/AlreadySubscribedException.php +++ b/app/Exceptions/AlreadySubscribedException.php @@ -3,11 +3,8 @@ declare(strict_types=1); class FreshRSS_AlreadySubscribed_Exception extends Minz_Exception { - private string $feedName = ''; - - public function __construct(string $url, string $feedName) { + public function __construct(string $url, private readonly string $feedName) { parent::__construct('Already subscribed! ' . $url, 2135); - $this->feedName = $feedName; } public function feedName(): string { diff --git a/app/Exceptions/BadUrlException.php b/app/Exceptions/BadUrlException.php index c7111a41f..654d03c18 100644 --- a/app/Exceptions/BadUrlException.php +++ b/app/Exceptions/BadUrlException.php @@ -2,7 +2,6 @@ declare(strict_types=1); class FreshRSS_BadUrl_Exception extends FreshRSS_Feed_Exception { - public function __construct(string $url) { parent::__construct('`' . $url . '` is not a valid URL'); } diff --git a/app/Exceptions/ZipException.php b/app/Exceptions/ZipException.php index 57176ab5f..d876c296c 100644 --- a/app/Exceptions/ZipException.php +++ b/app/Exceptions/ZipException.php @@ -3,11 +3,8 @@ declare(strict_types=1); class FreshRSS_Zip_Exception extends Minz_Exception { - private int $zipErrorCode = 0; - - public function __construct(int $zipErrorCode) { + public function __construct(private readonly int $zipErrorCode) { parent::__construct('ZIP error!', 2141); - $this->zipErrorCode = $zipErrorCode; } public function zipErrorCode(): int { diff --git a/app/Models/BooleanSearch.php b/app/Models/BooleanSearch.php index 50f8feea1..375705036 100644 --- a/app/Models/BooleanSearch.php +++ b/app/Models/BooleanSearch.php @@ -4,20 +4,24 @@ declare(strict_types=1); /** * Contains Boolean search from the search form. */ -class FreshRSS_BooleanSearch { +class FreshRSS_BooleanSearch implements \Stringable { private string $raw_input = ''; /** @var array<FreshRSS_BooleanSearch|FreshRSS_Search> */ private array $searches = []; /** - * @phpstan-var 'AND'|'OR'|'AND NOT'|'OR NOT' + * @param string $input + * @param int $level + * @param 'AND'|'OR'|'AND NOT'|'OR NOT' $operator + * @param bool $allowUserQueries */ - private string $operator; - - /** @param 'AND'|'OR'|'AND NOT'|'OR NOT' $operator */ - public function __construct(string $input, int $level = 0, string $operator = 'AND', bool $allowUserQueries = true) { - $this->operator = $operator; + public function __construct( + string $input, + int $level = 0, + private readonly string $operator = 'AND', + bool $allowUserQueries = true + ) { $input = trim($input); if ($input === '') { return; diff --git a/app/Models/Category.php b/app/Models/Category.php index 5c346844a..cd8145e0c 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -243,9 +243,7 @@ class FreshRSS_Category extends Minz_Model { if ($this->feeds === null) { return; } - uasort($this->feeds, static function (FreshRSS_Feed $a, FreshRSS_Feed $b) { - return strnatcasecmp($a->name(), $b->name()); - }); + uasort($this->feeds, static fn(FreshRSS_Feed $a, FreshRSS_Feed $b) => strnatcasecmp($a->name(), $b->name())); } /** diff --git a/app/Models/Context.php b/app/Models/Context.php index 26212a0ef..f39fd0eca 100644 --- a/app/Models/Context.php +++ b/app/Models/Context.php @@ -347,24 +347,16 @@ final class FreshRSS_Context { $type = substr($get, 0, 1); $id = substr($get, 2); - switch ($type) { - case 'a': - return self::$current_get['all']; - case 'i': - return self::$current_get['important']; - case 's': - return self::$current_get['starred']; - case 'f': - return self::$current_get['feed'] == $id; - case 'c': - return self::$current_get['category'] == $id; - case 't': - return self::$current_get['tag'] == $id; - case 'T': - return self::$current_get['tags'] || self::$current_get['tag']; - default: - return false; - } + return match ($type) { + 'a' => self::$current_get['all'], + 'i' => self::$current_get['important'], + 's' => self::$current_get['starred'], + 'f' => self::$current_get['feed'] == $id, + 'c' => self::$current_get['category'] == $id, + 't' => self::$current_get['tag'] == $id, + 'T' => self::$current_get['tags'] || self::$current_get['tag'], + default => false, + }; } /** diff --git a/app/Models/Entry.php b/app/Models/Entry.php index 6e87fe5cd..747bebd71 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -168,7 +168,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') || str_starts_with($mime, 'image') || ($mime == '' && $length == 0 && preg_match('/[.](avif|gif|jpe?g|png|svg|webp)([?#]|$)/i', $elink)); } @@ -242,12 +242,12 @@ HTML; if (self::enclosureIsImage($enclosure)) { $content .= '<p class="enclosure-content"><img src="' . $elink . '" alt="" title="' . $etitle . '" /></p>'; - } elseif ($medium === 'audio' || strpos($mime, 'audio') === 0) { + } elseif ($medium === 'audio' || str_starts_with($mime, 'audio')) { $content .= '<p class="enclosure-content"><audio preload="none" src="' . $elink . ($length == null ? '' : '" data-length="' . (int)$length) . ($mime == '' ? '' : '" data-type="' . htmlspecialchars($mime, ENT_COMPAT, 'UTF-8')) . '" controls="controls" title="' . $etitle . '"></audio> <a download="" href="' . $elink . '">💾</a></p>'; - } elseif ($medium === 'video' || strpos($mime, 'video') === 0) { + } elseif ($medium === 'video' || str_starts_with($mime, 'video')) { $content .= '<p class="enclosure-content"><video preload="none" src="' . $elink . ($length == null ? '' : '" data-length="' . (int)$length) . ($mime == '' ? '' : '" data-type="' . htmlspecialchars($mime, ENT_COMPAT, 'UTF-8')) @@ -285,7 +285,7 @@ HTML; yield from $attributeEnclosures; } try { - $searchEnclosures = !is_iterable($attributeEnclosures) && (strpos($this->content, '<p class="enclosure-content') !== false); + $searchEnclosures = !is_iterable($attributeEnclosures) && (str_contains($this->content, '<p class="enclosure-content')); $searchBodyImages &= (stripos($this->content, '<img') !== false); $xpath = null; if ($searchEnclosures || $searchBodyImages) { @@ -498,7 +498,7 @@ HTML; public function _authors($value): void { $this->hash = ''; if (!is_array($value)) { - if (strpos($value, ';') !== false) { + if (str_contains($value, ';')) { $value = htmlspecialchars_decode($value, ENT_QUOTES); $value = preg_split('/\s*[;]\s*/', $value, -1, PREG_SPLIT_NO_EMPTY) ?: []; $value = Minz_Helper::htmlspecialchars_utf8($value); @@ -568,21 +568,13 @@ HTML; foreach ($booleanSearch->searches() as $filter) { if ($filter instanceof FreshRSS_BooleanSearch) { // BooleanSearches are combined by AND (default) or OR or AND NOT (special cases) operators and are recursive - switch ($filter->operator()) { - case 'OR': - $ok |= $this->matches($filter); - break; - case 'OR NOT': - $ok |= !$this->matches($filter); - break; - case 'AND NOT': - $ok &= !$this->matches($filter); - break; - case 'AND': - default: - $ok &= $this->matches($filter); - break; - } + match ($filter->operator()) { + 'AND' => $ok &= $this->matches($filter), + 'OR' => $ok |= $this->matches($filter), + 'AND NOT' => $ok &= !$this->matches($filter), + 'OR NOT' => $ok |= !$this->matches($filter), + default => $ok &= $this->matches($filter), + }; } elseif ($filter instanceof FreshRSS_Search) { // Searches are combined by OR and are not recursive $ok = true; @@ -836,7 +828,7 @@ HTML; $base = $xpath->evaluate('normalize-space(//base/@href)'); if ($base == false || !is_string($base)) { $base = $url; - } elseif (substr($base, 0, 2) === '//') { + } elseif (str_starts_with($base, '//')) { //Protocol-relative URLs "//www.example.net" $base = (parse_url($url, PHP_URL_SCHEME) ?? 'https') . ':' . $base; } diff --git a/app/Models/Factory.php b/app/Models/Factory.php index be96c0e58..6c140475e 100644 --- a/app/Models/Factory.php +++ b/app/Models/Factory.php @@ -14,79 +14,63 @@ class FreshRSS_Factory { * @throws Minz_ConfigurationNamespaceException|Minz_PDOConnectionException */ public static function createCategoryDao(?string $username = null): FreshRSS_CategoryDAO { - switch (FreshRSS_Context::systemConf()->db['type'] ?? '') { - case 'sqlite': - return new FreshRSS_CategoryDAOSQLite($username); - default: - return new FreshRSS_CategoryDAO($username); - } + return match (FreshRSS_Context::systemConf()->db['type'] ?? '') { + 'sqlite' => new FreshRSS_CategoryDAOSQLite($username), + default => new FreshRSS_CategoryDAO($username), + }; } /** * @throws Minz_ConfigurationNamespaceException|Minz_PDOConnectionException */ public static function createFeedDao(?string $username = null): FreshRSS_FeedDAO { - switch (FreshRSS_Context::systemConf()->db['type'] ?? '') { - case 'sqlite': - return new FreshRSS_FeedDAOSQLite($username); - default: - return new FreshRSS_FeedDAO($username); - } + return match (FreshRSS_Context::systemConf()->db['type'] ?? '') { + 'sqlite' => new FreshRSS_FeedDAOSQLite($username), + default => new FreshRSS_FeedDAO($username), + }; } /** * @throws Minz_ConfigurationNamespaceException|Minz_PDOConnectionException */ public static function createEntryDao(?string $username = null): FreshRSS_EntryDAO { - switch (FreshRSS_Context::systemConf()->db['type'] ?? '') { - case 'sqlite': - return new FreshRSS_EntryDAOSQLite($username); - case 'pgsql': - return new FreshRSS_EntryDAOPGSQL($username); - default: - return new FreshRSS_EntryDAO($username); - } + return match (FreshRSS_Context::systemConf()->db['type'] ?? '') { + 'sqlite' => new FreshRSS_EntryDAOSQLite($username), + 'pgsql' => new FreshRSS_EntryDAOPGSQL($username), + default => new FreshRSS_EntryDAO($username), + }; } /** * @throws Minz_ConfigurationNamespaceException|Minz_PDOConnectionException */ public static function createTagDao(?string $username = null): FreshRSS_TagDAO { - switch (FreshRSS_Context::systemConf()->db['type'] ?? '') { - case 'sqlite': - return new FreshRSS_TagDAOSQLite($username); - case 'pgsql': - return new FreshRSS_TagDAOPGSQL($username); - default: - return new FreshRSS_TagDAO($username); - } + return match (FreshRSS_Context::systemConf()->db['type'] ?? '') { + 'sqlite' => new FreshRSS_TagDAOSQLite($username), + 'pgsql' => new FreshRSS_TagDAOPGSQL($username), + default => new FreshRSS_TagDAO($username), + }; } /** * @throws Minz_ConfigurationNamespaceException|Minz_PDOConnectionException */ public static function createStatsDAO(?string $username = null): FreshRSS_StatsDAO { - switch (FreshRSS_Context::systemConf()->db['type'] ?? '') { - case 'sqlite': - return new FreshRSS_StatsDAOSQLite($username); - case 'pgsql': - return new FreshRSS_StatsDAOPGSQL($username); - default: - return new FreshRSS_StatsDAO($username); - } + return match (FreshRSS_Context::systemConf()->db['type'] ?? '') { + 'sqlite' => new FreshRSS_StatsDAOSQLite($username), + 'pgsql' => new FreshRSS_StatsDAOPGSQL($username), + default => new FreshRSS_StatsDAO($username), + }; } /** * @throws Minz_ConfigurationNamespaceException|Minz_PDOConnectionException */ public static function createDatabaseDAO(?string $username = null): FreshRSS_DatabaseDAO { - switch (FreshRSS_Context::systemConf()->db['type'] ?? '') { - case 'sqlite': - return new FreshRSS_DatabaseDAOSQLite($username); - case 'pgsql': - return new FreshRSS_DatabaseDAOPGSQL($username); - default: - return new FreshRSS_DatabaseDAO($username); - } + return match (FreshRSS_Context::systemConf()->db['type'] ?? '') { + 'sqlite' => new FreshRSS_DatabaseDAOSQLite($username), + 'pgsql' => new FreshRSS_DatabaseDAOPGSQL($username), + default => new FreshRSS_DatabaseDAO($username), + }; } } diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 2aa0baa9d..489062316 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -358,7 +358,7 @@ class FreshRSS_Feed extends Minz_Model { } else { $simplePie = customSimplePie($this->attributes(), $this->curlOptions()); $url = htmlspecialchars_decode($this->url, ENT_QUOTES); - if (substr($url, -11) === '#force_feed') { + if (str_ends_with($url, '#force_feed')) { $simplePie->force_feed(true); $url = substr($url, 0, -11); } @@ -1167,7 +1167,7 @@ class FreshRSS_Feed extends Minz_Model { ' via hub ' . $hubJson['hub'] . ' with callback ' . $callbackUrl . ': ' . $info['http_code'] . ' ' . $response, PSHB_LOG); - if (substr('' . $info['http_code'], 0, 1) == '2') { + if (str_starts_with('' . $info['http_code'], '2')) { return true; } else { $hubJson['lease_start'] = time(); //Prevent trying again too soon diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php index ea6e7fc55..bb4209eca 100644 --- a/app/Models/FeedDAO.php +++ b/app/Models/FeedDAO.php @@ -424,9 +424,7 @@ SQL; */ $feeds = self::daoToFeeds($res); - uasort($feeds, static function (FreshRSS_Feed $a, FreshRSS_Feed $b) { - return strnatcasecmp($a->name(), $b->name()); - }); + uasort($feeds, static fn(FreshRSS_Feed $a, FreshRSS_Feed $b) => strnatcasecmp($a->name(), $b->name())); return $feeds; } diff --git a/app/Models/FilterAction.php b/app/Models/FilterAction.php index bf5a79fe7..eb8ea8502 100644 --- a/app/Models/FilterAction.php +++ b/app/Models/FilterAction.php @@ -3,13 +3,11 @@ declare(strict_types=1); class FreshRSS_FilterAction { - private FreshRSS_BooleanSearch $booleanSearch; /** @var array<string>|null */ private ?array $actions = null; /** @param array<string> $actions */ - private function __construct(FreshRSS_BooleanSearch $booleanSearch, array $actions) { - $this->booleanSearch = $booleanSearch; + private function __construct(private readonly FreshRSS_BooleanSearch $booleanSearch, array $actions) { $this->_actions($actions); } diff --git a/app/Models/ReadingMode.php b/app/Models/ReadingMode.php index 035b22114..60c7e76e1 100644 --- a/app/Models/ReadingMode.php +++ b/app/Models/ReadingMode.php @@ -6,23 +6,14 @@ declare(strict_types=1); */ class FreshRSS_ReadingMode { - protected string $id; protected string $name; - protected string $title; - /** @var array{c:string,a:string,params:array<string,mixed>} */ - protected array $urlParams; - protected bool $isActive = false; /** * ReadingMode constructor. * @param array{c:string,a:string,params:array<string,mixed>} $urlParams */ - public function __construct(string $id, string $title, array $urlParams, bool $active) { - $this->id = $id; - $this->name = _i($id); - $this->title = $title; - $this->urlParams = $urlParams; - $this->isActive = $active; + public function __construct(protected string $id, protected string $title, protected array $urlParams, protected bool $isActive) { + $this->name = _i($this->id); } public function getId(): string { diff --git a/app/Models/Search.php b/app/Models/Search.php index 45fa742be..4a006c2d0 100644 --- a/app/Models/Search.php +++ b/app/Models/Search.php @@ -9,7 +9,7 @@ require_once(LIB_PATH . '/lib_date.php'); * It allows to extract meaningful bits of the search and store them in a * convenient object */ -class FreshRSS_Search { +class FreshRSS_Search implements \Stringable { /** * This contains the user input string diff --git a/app/Models/Share.php b/app/Models/Share.php index 2df9dd4d9..847127466 100644 --- a/app/Models/Share.php +++ b/app/Models/Share.php @@ -68,33 +68,20 @@ class FreshRSS_Share { public static function get(string $type): ?FreshRSS_Share { return self::$list_sharing[$type] ?? null; } - - - private string $type; - private string $name; - private string $url_transform; - /** @var array<callable>|array<string,array<callable>> */ - private array $transforms; + private readonly string $name; /** * @phpstan-var 'simple'|'advanced' */ - private string $form_type; - private string $help_url; + private readonly string $form_type; private ?string $custom_name = null; private ?string $base_url = null; private ?string $id = null; private ?string $title = null; private ?string $link = null; - private bool $isDeprecated; /** * @phpstan-var 'GET'|'POST' */ private string $method; - private ?string $field; - /** - * @phpstan-var 'button'|null - */ - private ?string $HTMLtag; /** * Create a FreshRSS_Share object. @@ -108,15 +95,18 @@ class FreshRSS_Share { * @param 'GET'|'POST' $method defines the sharing method (GET or POST) * @param 'button'|null $HTMLtag */ - 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) { - $this->type = $type; - $this->name = _t('gen.share.' . $type); - $this->url_transform = $url_transform; - $this->help_url = $help_url; - $this->HTMLtag = $HTMLtag; - $this->isDeprecated = $isDeprecated; - $this->transforms = $transforms; + private function __construct( + private readonly string $type, + private readonly string $url_transform, + private array $transforms, + string $form_type, + private readonly string $help_url, + string $method, + private ?string $field, + private readonly ?string $HTMLtag, + private readonly bool $isDeprecated = false + ) { + $this->name = _t('gen.share.' . $this->type); if (!in_array($form_type, ['simple', 'advanced'], true)) { $form_type = 'simple'; @@ -126,7 +116,6 @@ class FreshRSS_Share { $method = 'GET'; } $this->method = $method; - $this->field = $field; } /** diff --git a/app/Models/StatsDAO.php b/app/Models/StatsDAO.php index c9753cf2c..6782bd7ee 100644 --- a/app/Models/StatsDAO.php +++ b/app/Models/StatsDAO.php @@ -147,19 +147,12 @@ SQL; if ($res == false) { return []; } - switch ($period) { - case '%H': - $periodMax = 24; - break; - case '%w': - $periodMax = 7; - break; - case '%m': - $periodMax = 12; - break; - default: - $periodMax = 30; - } + $periodMax = match ($period) { + '%H' => 24, + '%w' => 7, + '%m' => 12, + default => 30, + }; $repartition = array_fill(0, $periodMax, 0); foreach ($res as $value) { diff --git a/app/Models/StatsDAOPGSQL.php b/app/Models/StatsDAOPGSQL.php index ba5cbfca1..5e3476808 100644 --- a/app/Models/StatsDAOPGSQL.php +++ b/app/Models/StatsDAOPGSQL.php @@ -57,19 +57,12 @@ SQL; return []; } - switch ($period) { - case 'hour': - $periodMax = 24; - break; - case 'day': - $periodMax = 7; - break; - case 'month': - $periodMax = 12; - break; - default: - $periodMax = 30; - } + $periodMax = match ($period) { + 'hour' => 24, + 'day' => 7, + 'month' => 12, + default => 30, + }; $repartition = array_fill(0, $periodMax, 0); foreach ($res as $value) { diff --git a/app/Models/StatsDAOSQLite.php b/app/Models/StatsDAOSQLite.php index c45951069..4e51615fc 100644 --- a/app/Models/StatsDAOSQLite.php +++ b/app/Models/StatsDAOSQLite.php @@ -32,19 +32,12 @@ SQL; return []; } - switch ($period) { - case '%H': - $periodMax = 24; - break; - case '%w': - $periodMax = 7; - break; - case '%m': - $periodMax = 12; - break; - default: - $periodMax = 30; - } + $periodMax = match ($period) { + '%H' => 24, + '%w' => 7, + '%m' => 12, + default => 30, + }; $repartition = array_fill(0, $periodMax, 0); foreach ($res as $value) { diff --git a/app/Models/Themes.php b/app/Models/Themes.php index a5167c8e8..2a55a84db 100644 --- a/app/Models/Themes.php +++ b/app/Models/Themes.php @@ -165,14 +165,11 @@ class FreshRSS_Themes extends Minz_Model { } } - switch ($type) { - case self::ICON_URL: - return Minz_Url::display($url); - case self::ICON_IMG: - return '<img class="icon" src="' . Minz_Url::display($url) . '" loading="lazy" alt="' . $alt . '"' . $title . ' />'; - case self::ICON_EMOJI: - default: - return '<span class="icon"' . $title . '>' . $alt . '</span>'; - } + return match ($type) { + self::ICON_URL => Minz_Url::display($url), + self::ICON_IMG => '<img class="icon" src="' . Minz_Url::display($url) . '" loading="lazy" alt="' . $alt . '"' . $title . ' />', + self::ICON_EMOJI, => '<span class="icon"' . $title . '>' . $alt . '</span>', + default => '<span class="icon"' . $title . '>' . $alt . '</span>', + }; } } diff --git a/app/Models/UserQuery.php b/app/Models/UserQuery.php index 1ec8ee148..d3a56bb6a 100644 --- a/app/Models/UserQuery.php +++ b/app/Models/UserQuery.php @@ -8,7 +8,6 @@ declare(strict_types=1); * easy way. */ class FreshRSS_UserQuery { - private bool $deprecated = false; private string $get = ''; private string $get_name = ''; @@ -16,16 +15,12 @@ class FreshRSS_UserQuery { /** XML-encoded name */ private string $name = ''; private string $order = ''; - private FreshRSS_BooleanSearch $search; + private readonly FreshRSS_BooleanSearch $search; private int $state = 0; private string $url = ''; private string $token = ''; private bool $shareRss = false; private bool $shareOpml = false; - /** @var array<int,FreshRSS_Category> $categories */ - private array $categories; - /** @var array<int,FreshRSS_Tag> $labels */ - private array $labels; /** XML-encoded description */ private string $description = ''; private string $imageUrl = ''; @@ -48,9 +43,11 @@ class FreshRSS_UserQuery { * @param array<int,FreshRSS_Category> $categories * @param array<int,FreshRSS_Tag> $labels */ - public function __construct(array $query, array $categories, array $labels) { - $this->categories = $categories; - $this->labels = $labels; + public function __construct( + array $query, + private array $categories, + private array $labels, + ) { if (isset($query['get'])) { $this->parseGet($query['get']); } else { diff --git a/app/Models/View.php b/app/Models/View.php index 3c3b3a2e0..4ce837922 100644 --- a/app/Models/View.php +++ b/app/Models/View.php @@ -12,8 +12,8 @@ class FreshRSS_View extends Minz_View { public $callbackBeforePagination; /** @var array<int,FreshRSS_Category> */ public array $categories; - public ?FreshRSS_Category $category; - public ?FreshRSS_Tag $tag; + public ?FreshRSS_Category $category = null; + public ?FreshRSS_Tag $tag = null; public string $current_user; /** @var iterable<FreshRSS_Entry> */ public $entries; @@ -120,10 +120,10 @@ class FreshRSS_View extends Minz_View { // Extensions /** @var array<array{'name':string,'author':string,'description':string,'version':string,'entrypoint':string,'type':'system'|'user','url':string,'method':string,'directory':string}> */ public array $available_extensions; - public ?Minz_Extension $ext_details; + public ?Minz_Extension $ext_details = null; /** @var array{'system':array<Minz_Extension>,'user':array<Minz_Extension>} */ public array $extension_list; - public ?Minz_Extension $extension; + public ?Minz_Extension $extension = null; /** @var array<string,string> */ public array $extensions_installed; diff --git a/app/Services/ExportService.php b/app/Services/ExportService.php index c532308d7..797aadbb5 100644 --- a/app/Services/ExportService.php +++ b/app/Services/ExportService.php @@ -6,15 +6,13 @@ declare(strict_types=1); */ class FreshRSS_Export_Service { - private string $username; + private readonly FreshRSS_CategoryDAO $category_dao; - private FreshRSS_CategoryDAO $category_dao; + private readonly FreshRSS_FeedDAO $feed_dao; - private FreshRSS_FeedDAO $feed_dao; + private readonly FreshRSS_EntryDAO $entry_dao; - private FreshRSS_EntryDAO $entry_dao; - - private FreshRSS_TagDAO $tag_dao; + private readonly FreshRSS_TagDAO $tag_dao; final public const FRSS_NAMESPACE = 'https://freshrss.org/opml'; final public const TYPE_HTML_XPATH = 'HTML+XPath'; @@ -28,12 +26,10 @@ class FreshRSS_Export_Service { /** * Initialize the service for the given user. */ - public function __construct(string $username) { - $this->username = $username; - - $this->category_dao = FreshRSS_Factory::createCategoryDao($username); - $this->feed_dao = FreshRSS_Factory::createFeedDao($username); - $this->entry_dao = FreshRSS_Factory::createEntryDao($username); + public function __construct(private readonly string $username) { + $this->category_dao = FreshRSS_Factory::createCategoryDao($this->username); + $this->feed_dao = FreshRSS_Factory::createFeedDao($this->username); + $this->entry_dao = FreshRSS_Factory::createEntryDao($this->username); $this->tag_dao = FreshRSS_Factory::createTagDao(); } diff --git a/app/Services/ImportService.php b/app/Services/ImportService.php index 298c0ec21..51ab106ca 100644 --- a/app/Services/ImportService.php +++ b/app/Services/ImportService.php @@ -6,9 +6,9 @@ declare(strict_types=1); */ class FreshRSS_Import_Service { - private FreshRSS_CategoryDAO $catDAO; + private readonly FreshRSS_CategoryDAO $catDAO; - private FreshRSS_FeedDAO $feedDAO; + private readonly FreshRSS_FeedDAO $feedDAO; /** true if success, false otherwise */ private bool $lastStatus; diff --git a/app/Utils/dotNotationUtil.php b/app/Utils/dotNotationUtil.php index 73addbe74..620ed7db1 100644 --- a/app/Utils/dotNotationUtil.php +++ b/app/Utils/dotNotationUtil.php @@ -31,7 +31,7 @@ final class FreshRSS_dotNotation_Util if (static::exists($array, $key)) { return $array[$key]; } - if (strpos($key, '.') === false) { + if (str_contains($key, '.') === false) { return $array[$key] ?? static::value($default); } foreach (explode('.', $key) as $segment) { diff --git a/app/layout/nav_menu.phtml b/app/layout/nav_menu.phtml index f8b687f74..c4aff5c55 100644 --- a/app/layout/nav_menu.phtml +++ b/app/layout/nav_menu.phtml @@ -12,12 +12,12 @@ <?php if (FreshRSS_Auth::hasAccess()) { ?> <div id="nav_menu_actions" class="group"> <?php - $states = array( + $states = [ 'read' => FreshRSS_Entry::STATE_READ, 'unread' => FreshRSS_Entry::STATE_NOT_READ, 'starred' => FreshRSS_Entry::STATE_FAVORITE, 'non-starred' => FreshRSS_Entry::STATE_NOT_FAVORITE, - ); + ]; foreach ($states as $state_str => $state) { $state_enabled = FreshRSS_Context::isStateEnabled($state); @@ -110,17 +110,17 @@ $string_mark = _t('index.menu.mark_cat_read'); } - $mark_read_url = array( + $mark_read_url = [ 'c' => 'entry', 'a' => 'read', - 'params' => array( + 'params' => [ 'get' => $get, 'nextGet' => FreshRSS_Context::$next_get, 'idMax' => FreshRSS_Context::$id_max, 'search' => htmlspecialchars_decode(FreshRSS_Context::$search->getRawInput(), ENT_QUOTES), 'state' => FreshRSS_Context::$state, - ), - ); + ], + ]; $mark_unread_url = $mark_read_url; $mark_unread_url['params']['is_read'] = '0'; diff --git a/app/views/auth/index.phtml b/app/views/auth/index.phtml index e41223609..ebdd8a992 100644 --- a/app/views/auth/index.phtml +++ b/app/views/auth/index.phtml @@ -57,7 +57,7 @@ FreshRSS_Context::systemConf()->unsafe_autologin_enabled ? ' checked="checked"' : '', FreshRSS_Auth::accessNeedsAction() ? '' : ' disabled="disabled"' ?> data-leave-validation="<?= FreshRSS_Context::systemConf()->unsafe_autologin_enabled ?>"/> <?= _t('admin.auth.unsafe_autologin') ?> - <kbd><?= Minz_Url::display(array('c' => 'auth', 'a' => 'login', 'params' => array('u' => 'alice', 'p' => '1234')), 'html', true) ?></kbd> + <kbd><?= Minz_Url::display(['c' => 'auth', 'a' => 'login', 'params' => ['u' => 'alice', 'p' => '1234']], 'html', true) ?></kbd> </label> </div> </div> diff --git a/app/views/auth/register.phtml b/app/views/auth/register.phtml index 953b07b0d..fee221708 100644 --- a/app/views/auth/register.phtml +++ b/app/views/auth/register.phtml @@ -69,7 +69,7 @@ <div class="form-group form-group-actions"> <?php $redirect_url = urlencode(Minz_Url::display( - array('c' => 'index', 'a' => 'index'), + ['c' => 'index', 'a' => 'index'], 'php', true )); ?> diff --git a/app/views/configure/archiving.phtml b/app/views/configure/archiving.phtml index 7ab8a2d9a..61095205e 100644 --- a/app/views/configure/archiving.phtml +++ b/app/views/configure/archiving.phtml @@ -19,11 +19,11 @@ <div class="group-controls"> <select class="number" name="ttl_default" id="ttl_default" required="required" data-leave-validation="<?= FreshRSS_Context::userConf()->ttl_default ?>"><?php $found = false; - foreach (array(1200 => '20min', 1500 => '25min', 1800 => '30min', 2700 => '45min', + foreach ([1200 => '20min', 1500 => '25min', 1800 => '30min', 2700 => '45min', 3600 => '1h', 5400 => '1.5h', 7200 => '2h', 10800 => '3h', 14400 => '4h', 18800 => '5h', 21600 => '6h', 25200 => '7h', 28800 => '8h', 36000 => '10h', 43200 => '12h', 64800 => '18h', 86400 => '1d', 129600 => '1.5d', 172800 => '2d', 259200 => '3d', 345600 => '4d', 432000 => '5d', 518400 => '6d', - 604800 => '1wk') as $v => $t) { + 604800 => '1wk'] as $v => $t) { echo '<option value="' . $v . (FreshRSS_Context::userConf()->ttl_default == $v ? '" selected="selected' : '') . '">' . $t . '</option>'; if (FreshRSS_Context::userConf()->ttl_default == $v) { $found = true; diff --git a/app/views/entry/bookmark.phtml b/app/views/entry/bookmark.phtml index 192e805a0..81647352c 100644 --- a/app/views/entry/bookmark.phtml +++ b/app/views/entry/bookmark.phtml @@ -4,16 +4,16 @@ declare(strict_types=1); header('Content-Type: application/json; charset=UTF-8'); -$url = array( +$url = [ 'c' => Minz_Request::controllerName(), 'a' => Minz_Request::actionName(), 'params' => $_GET, -); +]; $url['params']['is_favorite'] = (Minz_Request::paramTernary('is_favorite') ?? true) ? '0' : '1'; FreshRSS::loadStylesAndScripts(); -echo json_encode(array( - 'url' => str_ireplace('&', '&', Minz_Url::display($url)), - 'icon' => _i($url['params']['is_favorite'] === '1' ? 'non-starred' : 'starred') - )); +echo json_encode([ + 'url' => str_ireplace('&', '&', Minz_Url::display($url)), + 'icon' => _i($url['params']['is_favorite'] === '1' ? 'non-starred' : 'starred') +]); diff --git a/app/views/helpers/export/articles.phtml b/app/views/helpers/export/articles.phtml index f62573dd4..20001fb59 100644 --- a/app/views/helpers/export/articles.phtml +++ b/app/views/helpers/export/articles.phtml @@ -5,18 +5,18 @@ $username = Minz_User::name() ?? Minz_User::INTERNAL_USER; $options = JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE; -$articles = array( +$articles = [ 'id' => 'user/' . str_replace('/', '', $username) . '/state/org.freshrss/' . $this->type, 'title' => $this->list_title, 'author' => $username, - 'items' => array(), -); + 'items' => [], +]; echo rtrim(json_encode($articles, $options) ?: '', " ]}\n\r\t"), "\n"; $first = true; if (empty($this->entryIdsTagNames)) { - $this->entryIdsTagNames = array(); + $this->entryIdsTagNames = []; } foreach ($this->entries as $entry) { diff --git a/app/views/helpers/feed/update.phtml b/app/views/helpers/feed/update.phtml index c9f8fea62..b6ae16f34 100644 --- a/app/views/helpers/feed/update.phtml +++ b/app/views/helpers/feed/update.phtml @@ -129,11 +129,11 @@ <div class="group-controls"> <select class="w50" name="ttl" id="ttl" required="required"><?php $found = false; - foreach (array(FreshRSS_Feed::TTL_DEFAULT => _t('gen.short.by_default'), 900 => '15min', 1200 => '20min', 1500 => '25min', 1800 => '30min', 2700 => '45min', + foreach ([FreshRSS_Feed::TTL_DEFAULT => _t('gen.short.by_default'), 900 => '15min', 1200 => '20min', 1500 => '25min', 1800 => '30min', 2700 => '45min', 3600 => '1h', 5400 => '1.5h', 7200 => '2h', 10800 => '3h', 14400 => '4h', 18800 => '5h', 21600 => '6h', 25200 => '7h', 28800 => '8h', 36000 => '10h', 43200 => '12h', 64800 => '18h', 86400 => '1d', 129600 => '1.5d', 172800 => '2d', 259200 => '3d', 345600 => '4d', 432000 => '5d', 518400 => '6d', - 604800 => '1wk', 1209600 => '2wk', 1814400 => '3wk', 2419200 => '4wk', 2629744 => '1mo') as $v => $t) { + 604800 => '1wk', 1209600 => '2wk', 1814400 => '3wk', 2419200 => '4wk', 2629744 => '1mo'] as $v => $t) { echo '<option value="' . $v . ($this->feed->ttl() === $v ? '" selected="selected' : '') . '">' . $t . '</option>'; if ($this->feed->ttl() == $v) { $found = true; diff --git a/app/views/helpers/javascript_vars.phtml b/app/views/helpers/javascript_vars.phtml index 54ba2917f..db6e8cf3b 100644 --- a/app/views/helpers/javascript_vars.phtml +++ b/app/views/helpers/javascript_vars.phtml @@ -4,8 +4,8 @@ declare(strict_types=1); $mark = FreshRSS_Context::userConf()->mark_when; $s = FreshRSS_Context::userConf()->shortcuts; $extData = Minz_ExtensionManager::callHook('js_vars', []); -echo htmlspecialchars(json_encode(array( - 'context' => array( +echo htmlspecialchars(json_encode([ + 'context' => [ 'anonymous' => !FreshRSS_Auth::hasAccess(), 'auto_remove_article' => !!FreshRSS_Context::isAutoRemoveAvailable(), 'hide_posts' => !(FreshRSS_Context::userConf()->display_posts || Minz_Request::actionName() === 'reader'), @@ -30,8 +30,8 @@ echo htmlspecialchars(json_encode(array( 'feed.js' => @filemtime(PUBLIC_PATH . '/scripts/feed.js'), ], 'version' => FRESHRSS_VERSION, - ), - 'shortcuts' => array( + ], + 'shortcuts' => [ 'actualize' => @$s['actualize'], 'mark_read' => @$s['mark_read'], 'mark_favorite' => @$s['mark_favorite'], @@ -55,15 +55,15 @@ echo htmlspecialchars(json_encode(array( 'reading_view' => @$s['reading_view'], 'rss_view' => @$s['rss_view'], 'toggle_media' => @$s['toggle_media'], - ), - 'urls' => array( + ], + 'urls' => [ 'index' => _url('index', 'index'), - 'login' => Minz_Url::display(array('c' => 'auth', 'a' => 'login'), 'php'), - 'logout' => Minz_Url::display(array('c' => 'auth', 'a' => 'logout'), 'php'), + 'login' => Minz_Url::display(['c' => 'auth', 'a' => 'login'], 'php'), + 'logout' => Minz_Url::display(['c' => 'auth', 'a' => 'logout'], 'php'), 'help' => FRESHRSS_WIKI, - 'shortcuts' => Minz_Url::display(array('c' => 'configure', 'a' => 'shortcut'), 'php'), - ), - 'i18n' => array( + 'shortcuts' => Minz_Url::display(['c' => 'configure', 'a' => 'shortcut'], 'php'), + ], + 'i18n' => [ 'confirmation_default' => _t('gen.js.confirm_action'), 'notif_title_articles' => _t('gen.js.feedback.title_new_articles'), 'notif_body_new_articles' => _t('gen.js.feedback.body_new_articles'), @@ -72,10 +72,10 @@ echo htmlspecialchars(json_encode(array( 'category_empty' => _t('gen.js.category_empty'), 'labels_empty' => _t('gen.js.labels_empty'), 'language' => FreshRSS_Context::userConf()->language, - ), - 'icons' => array( + ], + 'icons' => [ 'read' => rawurlencode(_i('read')), 'unread' => rawurlencode(_i('unread')), - ), + ], 'extensions' => $extData, -), JSON_UNESCAPED_UNICODE) ?: '', ENT_NOQUOTES, 'UTF-8'); +], JSON_UNESCAPED_UNICODE) ?: '', ENT_NOQUOTES, 'UTF-8'); diff --git a/app/views/helpers/logs_pagination.phtml b/app/views/helpers/logs_pagination.phtml index 309a80e6b..77e3f3c82 100644 --- a/app/views/helpers/logs_pagination.phtml +++ b/app/views/helpers/logs_pagination.phtml @@ -13,14 +13,14 @@ $params[$getteur] = 1; ?> <li class="item pager-first"> - <a href="<?= Minz_Url::display(array('c' => $c, 'a' => $a, 'params' => $params)) ?>">« <?= _t('conf.logs.pagination.first') ?></a> + <a href="<?= Minz_Url::display(['c' => $c, 'a' => $a, 'params' => $params]) ?>">« <?= _t('conf.logs.pagination.first') ?></a> </li> <?php $params[$getteur] = $this->currentPage - 1; ?> <li class="item pager-previous"> <?php if ($this->currentPage > 1) { ?> - <a href="<?= Minz_Url::display(array('c' => $c, 'a' => $a, 'params' => $params)) ?>">‹ <?= _t('conf.logs.pagination.previous') ?></a> + <a href="<?= Minz_Url::display(['c' => $c, 'a' => $a, 'params' => $params]) ?>">‹ <?= _t('conf.logs.pagination.previous') ?></a> <?php } ?> </li> @@ -39,7 +39,7 @@ $class = ' active'; $aria = 'true'; } ?> - <li class="item<?= $class ?>"><a href="<?= Minz_Url::display(array('c' => $c, 'a' => $a, 'params' => $params)) ?>" aria-current="<?= $aria ?>"><?= $i ?></a></li> + <li class="item<?= $class ?>"><a href="<?= Minz_Url::display(['c' => $c, 'a' => $a, 'params' => $params]) ?>" aria-current="<?= $aria ?>"><?= $i ?></a></li> <?php } } ?> @@ -52,13 +52,13 @@ <li class="item pager-next"> <?php if ($this->currentPage < $this->nbPage) { ?> - <a href="<?= Minz_Url::display(array('c' => $c, 'a' => $a, 'params' => $params)) ?>"><?= _t('conf.logs.pagination.next') ?> ›</a> + <a href="<?= Minz_Url::display(['c' => $c, 'a' => $a, 'params' => $params]) ?>"><?= _t('conf.logs.pagination.next') ?> ›</a> <?php } ?> </li> <?php $params[$getteur] = $this->nbPage; ?> <li class="item pager-last"> - <a href="<?= Minz_Url::display(array('c' => $c, 'a' => $a, 'params' => $params)) ?>"><?= _t('conf.logs.pagination.last') ?> »</a> + <a href="<?= Minz_Url::display(['c' => $c, 'a' => $a, 'params' => $params]) ?>"><?= _t('conf.logs.pagination.last') ?> »</a> </li> </ul> </nav> diff --git a/app/views/index/global.phtml b/app/views/index/global.phtml index decde4cce..72916f1a0 100644 --- a/app/views/index/global.phtml +++ b/app/views/index/global.phtml @@ -42,11 +42,11 @@ $params = $_GET; unset($params['c']); unset($params['a']); - $url_base = array( + $url_base = [ 'c' => 'index', 'a' => 'normal', 'params' => $params, - ); + ]; $unreadArticles = 0; diff --git a/app/views/javascript/nbUnreadsPerFeed.phtml b/app/views/javascript/nbUnreadsPerFeed.phtml index f82893f13..12993d297 100644 --- a/app/views/javascript/nbUnreadsPerFeed.phtml +++ b/app/views/javascript/nbUnreadsPerFeed.phtml @@ -2,10 +2,10 @@ declare(strict_types=1); /** @var FreshRSS_ViewJavascript $this */ -$result = array( - 'feeds' => array(), - 'tags' => array(), -); +$result = [ + 'feeds' => [], + 'tags' => [], +]; foreach ($this->categories as $cat) { foreach ($cat->feeds() as $feed) { $result['feeds'][$feed->id()] = $feed->nbNotRead(); diff --git a/app/views/javascript/nonce.phtml b/app/views/javascript/nonce.phtml index e7dceb339..ee1e3ecb5 100644 --- a/app/views/javascript/nonce.phtml +++ b/app/views/javascript/nonce.phtml @@ -1,4 +1,4 @@ <?php declare(strict_types=1); /** @var FreshRSS_ViewJavascript $this */ -echo json_encode(array('salt1' => $this->salt1, 'nonce' => $this->nonce)); +echo json_encode(['salt1' => $this->salt1, 'nonce' => $this->nonce]); diff --git a/app/views/stats/idle.phtml b/app/views/stats/idle.phtml index 0c3ebc38f..cfef022c6 100644 --- a/app/views/stats/idle.phtml +++ b/app/views/stats/idle.phtml @@ -12,7 +12,7 @@ <?php $current_url = Minz_Url::display( - array('c' => 'stats', 'a' => 'idle'), + ['c' => 'stats', 'a' => 'idle'], 'php', true ); $nothing = true; diff --git a/app/views/stats/index.phtml b/app/views/stats/index.phtml index b24b859b8..0d144fcd5 100644 --- a/app/views/stats/index.phtml +++ b/app/views/stats/index.phtml @@ -102,12 +102,12 @@ <canvas id="statsFeedsPerCategory"></canvas> <script class="jsonData-stats" type="application/json"> <?php - echo json_encode(array( + echo json_encode([ 'canvasID' => 'statsFeedsPerCategory', 'charttype' => 'doughnut', 'data' => $this->feedByCategory['data'], 'labels' => $this->feedByCategory['label'], - ), JSON_UNESCAPED_UNICODE); + ], JSON_UNESCAPED_UNICODE); ?></script> </div> </div> @@ -118,12 +118,12 @@ <canvas id="statsEntriesPerCategory"></canvas> <script class="jsonData-stats" type="application/json"> <?php - echo json_encode(array( + echo json_encode([ 'canvasID' => 'statsEntriesPerCategory', 'charttype' => 'doughnut', 'data' => $this->entryByCategory['data'], 'labels' => $this->entryByCategory['label'], - ), JSON_UNESCAPED_UNICODE); + ], JSON_UNESCAPED_UNICODE); ?></script> </div> </div> diff --git a/app/views/stats/repartition.phtml b/app/views/stats/repartition.phtml index dd4ff9b29..c8edbf338 100644 --- a/app/views/stats/repartition.phtml +++ b/app/views/stats/repartition.phtml @@ -60,13 +60,13 @@ <canvas id="statsEntriesPerHour"></canvas> <script class="jsonData-stats" type="application/json"> <?php - echo json_encode(array( + echo json_encode([ 'canvasID' => 'statsEntriesPerHour', 'charttype' => 'bar', 'data' => $this->repartitionHour, 'label' => _t('admin.stats.entry_count'), 'xAxisLabels' => $this->hours24Labels - ), JSON_UNESCAPED_UNICODE); + ], JSON_UNESCAPED_UNICODE); ?></script> </div> </div> @@ -77,13 +77,13 @@ <canvas id="statsEntriesPerDayOfWeek"></canvas> <script class="jsonData-stats" type="application/json"> <?php - echo json_encode(array( + echo json_encode([ 'canvasID' => 'statsEntriesPerDayOfWeek', 'charttype' => 'bar', 'data' => $this->repartitionDayOfWeek, 'label' => _t('admin.stats.entry_count'), 'xAxisLabels' => $this->days, - ), JSON_UNESCAPED_UNICODE); + ], JSON_UNESCAPED_UNICODE); ?></script> </div> </div> @@ -94,13 +94,13 @@ <canvas id="statsEntriesPerMonth"></canvas> <script class="jsonData-stats" type="application/json"> <?php - echo json_encode(array( + echo json_encode([ 'canvasID' => 'statsEntriesPerMonth', 'charttype' => 'bar', 'data' => $this->repartitionMonth, 'label' => _t('admin.stats.entry_count'), 'xAxisLabels' => $this->months, - ), JSON_UNESCAPED_UNICODE); + ], JSON_UNESCAPED_UNICODE); ?></script> </div> </div> diff --git a/app/views/subscription/bookmarklet.phtml b/app/views/subscription/bookmarklet.phtml index d96f8a35b..0ea81b153 100644 --- a/app/views/subscription/bookmarklet.phtml +++ b/app/views/subscription/bookmarklet.phtml @@ -12,10 +12,10 @@ <h2><?= _t('sub.bookmarklet.title') ?></h2> <p><a class="btn btn-important" href="javascript:(function(){var%20url%20=%20location.href;var%20otherWindow=window.open('about:blank','_blank');otherWindow.opener=null;otherWindow.location='<?= - Minz_Url::display(array('c' => 'feed', 'a' => 'add'), 'html', true) ?>&url_rss='+encodeURIComponent(url);})();"><?= _t('sub.bookmarklet.label') ?></a></p> + Minz_Url::display(['c' => 'feed', 'a' => 'add'], 'html', true) ?>&url_rss='+encodeURIComponent(url);})();"><?= _t('sub.bookmarklet.label') ?></a></p> <?= _t('sub.bookmarklet.documentation') ?> <h2><?= _t('sub.api.title') ?></h2> <p><?= _t('sub.api.documentation') ?></p> - <kbd><?= Minz_Url::display(array('c' => 'feed', 'a' => 'add'), 'html', true) ?>&url_rss=%s</kbd> + <kbd><?= Minz_Url::display(['c' => 'feed', 'a' => 'add'], 'html', true) ?>&url_rss=%s</kbd> </main> diff --git a/app/views/user/profile.phtml b/app/views/user/profile.phtml index b2e8a7d7b..1c410334d 100644 --- a/app/views/user/profile.phtml +++ b/app/views/user/profile.phtml @@ -124,7 +124,7 @@ <div class="group-controls"> <?php $redirect_url = urlencode(Minz_Url::display( - array('c' => 'user', 'a' => 'profile'), + ['c' => 'user', 'a' => 'profile'], 'php', true )); ?> |
