aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> 2024-11-28 17:11:04 +0100
committerGravatar GitHub <noreply@github.com> 2024-11-28 17:11:04 +0100
commit15745d42b779ad14efde2932ab116f45eee39246 (patch)
tree2528a36184d8152d4f2d90dc73df680f84bbe1d1
parent604b186638276203c8495a3ee86da0cc240ab4d0 (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>
-rw-r--r--app/Controllers/authController.php23
-rw-r--r--app/Controllers/configureController.php2
-rw-r--r--app/Controllers/errorController.php4
-rwxr-xr-xapp/Controllers/feedController.php8
-rw-r--r--app/Controllers/importExportController.php51
-rw-r--r--app/Controllers/indexController.php4
-rw-r--r--app/Controllers/updateController.php7
-rw-r--r--app/Exceptions/AlreadySubscribedException.php5
-rw-r--r--app/Exceptions/BadUrlException.php1
-rw-r--r--app/Exceptions/ZipException.php5
-rw-r--r--app/Models/BooleanSearch.php18
-rw-r--r--app/Models/Category.php4
-rw-r--r--app/Models/Context.php28
-rw-r--r--app/Models/Entry.php34
-rw-r--r--app/Models/Factory.php72
-rw-r--r--app/Models/Feed.php4
-rw-r--r--app/Models/FeedDAO.php4
-rw-r--r--app/Models/FilterAction.php4
-rw-r--r--app/Models/ReadingMode.php13
-rw-r--r--app/Models/Search.php2
-rw-r--r--app/Models/Share.php39
-rw-r--r--app/Models/StatsDAO.php19
-rw-r--r--app/Models/StatsDAOPGSQL.php19
-rw-r--r--app/Models/StatsDAOSQLite.php19
-rw-r--r--app/Models/Themes.php15
-rw-r--r--app/Models/UserQuery.php15
-rw-r--r--app/Models/View.php8
-rw-r--r--app/Services/ExportService.php20
-rw-r--r--app/Services/ImportService.php4
-rw-r--r--app/Utils/dotNotationUtil.php2
-rw-r--r--app/layout/nav_menu.phtml12
-rw-r--r--app/views/auth/index.phtml2
-rw-r--r--app/views/auth/register.phtml2
-rw-r--r--app/views/configure/archiving.phtml4
-rw-r--r--app/views/entry/bookmark.phtml12
-rw-r--r--app/views/helpers/export/articles.phtml8
-rw-r--r--app/views/helpers/feed/update.phtml4
-rw-r--r--app/views/helpers/javascript_vars.phtml30
-rw-r--r--app/views/helpers/logs_pagination.phtml10
-rw-r--r--app/views/index/global.phtml4
-rw-r--r--app/views/javascript/nbUnreadsPerFeed.phtml8
-rw-r--r--app/views/javascript/nonce.phtml2
-rw-r--r--app/views/stats/idle.phtml2
-rw-r--r--app/views/stats/index.phtml8
-rw-r--r--app/views/stats/repartition.phtml12
-rw-r--r--app/views/subscription/bookmarklet.phtml4
-rw-r--r--app/views/user/profile.phtml2
-rw-r--r--cli/CliOption.php7
-rwxr-xr-xcli/create-user.php2
-rwxr-xr-xcli/do-install.php8
-rwxr-xr-xcli/export-zip-for-user.php6
-rw-r--r--cli/i18n/I18nCompletionValidator.php11
-rw-r--r--cli/i18n/I18nData.php11
-rw-r--r--cli/i18n/I18nUsageValidator.php11
-rw-r--r--cli/i18n/I18nValue.php4
-rwxr-xr-xcli/import-for-user.php2
-rwxr-xr-xcli/update-user.php2
-rwxr-xr-xcli/user-info.php4
-rw-r--r--config.default.php16
-rw-r--r--docs/en/admins/05_Configuring_email_validation.md4
-rw-r--r--docs/en/developers/05_Release_new_version.md4
-rw-r--r--docs/fr/developers/05_Release_new_version.md4
-rw-r--r--lib/Minz/Configuration.php4
-rw-r--r--lib/Minz/ExtensionManager.php98
-rw-r--r--lib/Minz/ModelArray.php2
-rw-r--r--lib/Minz/PdoPgsql.php2
-rw-r--r--lib/Minz/Request.php2
-rw-r--r--lib/Minz/Session.php2
-rw-r--r--lib/Minz/Translate.php16
-rw-r--r--lib/favicons.php6
-rw-r--r--lib/lib_date.php4
-rw-r--r--lib/lib_install.php6
-rw-r--r--lib/lib_rss.php26
-rw-r--r--p/api/fever.php2
-rw-r--r--p/api/greader.php201
-rw-r--r--p/api/pshb.php2
-rw-r--r--p/api/query.php2
-rw-r--r--p/ext.php5
-rw-r--r--p/f.php4
-rw-r--r--tests/app/Models/SearchTest.php104
-rw-r--r--tests/app/Models/UserQueryTest.php49
81 files changed, 532 insertions, 680 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('&amp;', '&', Minz_Url::display($url)),
- 'icon' => _i($url['params']['is_favorite'] === '1' ? 'non-starred' : 'starred')
- ));
+echo json_encode([
+ 'url' => str_ireplace('&amp;', '&', 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) ?>&amp;url_rss='+encodeURIComponent(url);})();"><?= _t('sub.bookmarklet.label') ?></a></p>
+ Minz_Url::display(['c' => 'feed', 'a' => 'add'], 'html', true) ?>&amp;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) ?>&amp;url_rss=%s</kbd>
+ <kbd><?= Minz_Url::display(['c' => 'feed', 'a' => 'add'], 'html', true) ?>&amp;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
));
?>
diff --git a/cli/CliOption.php b/cli/CliOption.php
index d0eace311..e92fbd804 100644
--- a/cli/CliOption.php
+++ b/cli/CliOption.php
@@ -5,18 +5,13 @@ final class CliOption {
public const VALUE_NONE = 'none';
public const VALUE_REQUIRED = 'required';
public const VALUE_OPTIONAL = 'optional';
-
- private string $longAlias;
- private ?string $shortAlias;
private string $valueTaken = self::VALUE_REQUIRED;
/** @var array{type:string,isArray:bool} $types */
private array $types = ['type' => 'string', 'isArray' => false];
private string $optionalValueDefault = '';
private ?string $deprecatedAlias = null;
- public function __construct(string $longAlias, ?string $shortAlias = null) {
- $this->longAlias = $longAlias;
- $this->shortAlias = $shortAlias;
+ public function __construct(private readonly string $longAlias, private readonly ?string $shortAlias = null) {
}
/** Sets this option to be treated as a flag. */
diff --git a/cli/create-user.php b/cli/create-user.php
index ae560b49e..067ea2eff 100755
--- a/cli/create-user.php
+++ b/cli/create-user.php
@@ -79,7 +79,7 @@ $values = array_filter($values);
$ok = FreshRSS_user_Controller::createUser(
$username,
- isset($cliOptions->email) ? $cliOptions->email : null,
+ $cliOptions->email ?? null,
$cliOptions->password ?? '',
$values,
!isset($cliOptions->noDefaultFeeds)
diff --git a/cli/do-install.php b/cli/do-install.php
index 483a443d9..8591f2299 100755
--- a/cli/do-install.php
+++ b/cli/do-install.php
@@ -92,10 +92,10 @@ $dbValues = [
'prefix' => $cliOptions->dbPrefix ?? null,
];
-$config = array(
- 'salt' => generateSalt(),
- 'db' => FreshRSS_Context::systemConf()->db,
- );
+$config = [
+ 'salt' => generateSalt(),
+ 'db' => FreshRSS_Context::systemConf()->db,
+];
$customConfigPath = DATA_PATH . '/config.custom.php';
if (file_exists($customConfigPath)) {
diff --git a/cli/export-zip-for-user.php b/cli/export-zip-for-user.php
index 304acc392..e030274d2 100755
--- a/cli/export-zip-for-user.php
+++ b/cli/export-zip-for-user.php
@@ -33,11 +33,11 @@ $number_entries = $cliOptions->maxFeedEntries;
$exported_files = [];
// First, we generate the OPML file
-list($filename, $content) = $export_service->generateOpml();
+[$filename, $content] = $export_service->generateOpml();
$exported_files[$filename] = $content;
// Then, labelled and starred entries
-list($filename, $content) = $export_service->generateStarredEntries('ST');
+[$filename, $content] = $export_service->generateStarredEntries('ST');
$exported_files[$filename] = $content;
// And a list of entries based on the complete list of feeds
@@ -46,7 +46,7 @@ $exported_files = array_merge($exported_files, $feeds_exported_files);
// Finally, we compress all these files into a single Zip archive and we output
// the content
-list($filename, $content) = $export_service->zip($exported_files);
+[$filename, $content] = $export_service->zip($exported_files);
echo $content;
invalidateHttpCache($username);
diff --git a/cli/i18n/I18nCompletionValidator.php b/cli/i18n/I18nCompletionValidator.php
index 2a42dc13f..28f8abed8 100644
--- a/cli/i18n/I18nCompletionValidator.php
+++ b/cli/i18n/I18nCompletionValidator.php
@@ -5,10 +5,6 @@ require_once __DIR__ . '/I18nValidatorInterface.php';
class I18nCompletionValidator implements I18nValidatorInterface {
- /** @var array<string,array<string,I18nValue>> */
- private array $reference;
- /** @var array<string,array<string,I18nValue>> */
- private array $language;
private int $totalEntries = 0;
private int $passEntries = 0;
private string $result = '';
@@ -17,9 +13,10 @@ class I18nCompletionValidator implements I18nValidatorInterface {
* @param array<string,array<string,I18nValue>> $reference
* @param array<string,array<string,I18nValue>> $language
*/
- public function __construct(array $reference, array $language) {
- $this->reference = $reference;
- $this->language = $language;
+ public function __construct(
+ private readonly array $reference,
+ private array $language,
+ ) {
}
#[\Override]
diff --git a/cli/i18n/I18nData.php b/cli/i18n/I18nData.php
index 6d5730a08..6f841e947 100644
--- a/cli/i18n/I18nData.php
+++ b/cli/i18n/I18nData.php
@@ -5,13 +5,8 @@ class I18nData {
public const REFERENCE_LANGUAGE = 'en';
- /** @var array<string,array<string,array<string,I18nValue>>> */
- private array $data;
-
/** @param array<string,array<string,array<string,I18nValue>>> $data */
- public function __construct(array $data) {
- $this->data = $data;
-
+ public function __construct(private array $data) {
$this->addMissingKeysFromReference();
$this->removeExtraKeysFromOtherLanguages();
$this->processValueStates();
@@ -144,7 +139,7 @@ class I18nData {
$keys = array_keys($this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)]);
$parent = $this->getParentKey($key);
- return array_values(array_filter($keys, static fn(string $element) => false !== strpos($element, $parent)));
+ return array_values(array_filter($keys, static fn(string $element) => str_contains($element, $parent)));
}
/**
@@ -185,7 +180,7 @@ class I18nData {
if ($element === $key) {
return false;
}
- return false !== strpos($element, $key);
+ return str_contains($element, $key);
}));
return count($children) !== 0;
diff --git a/cli/i18n/I18nUsageValidator.php b/cli/i18n/I18nUsageValidator.php
index dd514236b..89c88d222 100644
--- a/cli/i18n/I18nUsageValidator.php
+++ b/cli/i18n/I18nUsageValidator.php
@@ -5,10 +5,6 @@ require_once __DIR__ . '/I18nValidatorInterface.php';
class I18nUsageValidator implements I18nValidatorInterface {
- /** @var array<string> */
- private array $code;
- /** @var array<string,array<string,I18nValue>> */
- private array $reference;
private int $totalEntries = 0;
private int $failedEntries = 0;
private string $result = '';
@@ -17,9 +13,10 @@ class I18nUsageValidator implements I18nValidatorInterface {
* @param array<string,array<string,I18nValue>> $reference
* @param array<string> $code
*/
- public function __construct(array $reference, array $code) {
- $this->code = $code;
- $this->reference = $reference;
+ public function __construct(
+ private readonly array $reference,
+ private readonly array $code,
+ ) {
}
#[\Override]
diff --git a/cli/i18n/I18nValue.php b/cli/i18n/I18nValue.php
index aa2a670e1..ba6465062 100644
--- a/cli/i18n/I18nValue.php
+++ b/cli/i18n/I18nValue.php
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);
-class I18nValue {
+class I18nValue implements \Stringable {
private const STATE_DIRTY = 'dirty';
public const STATE_IGNORE = 'ignore';
private const STATE_TODO = 'todo';
@@ -11,7 +11,7 @@ class I18nValue {
self::STATE_TODO,
];
- private string $value;
+ private readonly string $value;
private ?string $state = null;
/** @param I18nValue|string $data */
diff --git a/cli/import-for-user.php b/cli/import-for-user.php
index 4c4db8405..17dc9750e 100755
--- a/cli/import-for-user.php
+++ b/cli/import-for-user.php
@@ -34,7 +34,7 @@ $importController = new FreshRSS_importExport_Controller();
$ok = false;
try {
$ok = $importController->importFile($filename, $filename, $username);
-} catch (FreshRSS_ZipMissing_Exception $zme) {
+} catch (FreshRSS_ZipMissing_Exception) {
fail('FreshRSS error: Lacking php-zip extension!');
} catch (FreshRSS_Zip_Exception $ze) {
fail('FreshRSS error: ZIP archive cannot be imported! Error code: ' . $ze->zipErrorCode());
diff --git a/cli/update-user.php b/cli/update-user.php
index 553025d2b..946f296fa 100755
--- a/cli/update-user.php
+++ b/cli/update-user.php
@@ -70,7 +70,7 @@ $values = array_filter($values);
$ok = FreshRSS_user_Controller::updateUser(
$username,
- isset($cliOptions->email) ? $cliOptions->email : null,
+ $cliOptions->email ?? null,
$cliOptions->password ?? '',
$values);
diff --git a/cli/user-info.php b/cli/user-info.php
index 6674ebc6b..5895d9b1d 100755
--- a/cli/user-info.php
+++ b/cli/user-info.php
@@ -69,7 +69,7 @@ foreach ($users as $username) {
$nbFavorites = $entryDAO->countUnreadReadFavorites();
$feedList = $feedDAO->listFeedsIds();
- $data = array(
+ $data = [
'default' => $username === FreshRSS_Context::systemConf()->default_user ? '*' : '',
'user' => $username,
'admin' => FreshRSS_Context::userConf()->is_admin ? '*' : '',
@@ -84,7 +84,7 @@ foreach ($users as $username) {
'tags' => $tagDAO->count(),
'lang' => FreshRSS_Context::userConf()->language,
'mail_login' => FreshRSS_Context::userConf()->mail_login,
- );
+ ];
if (isset($cliOptions->humanReadable)) { //Human format
$data['last_user_activity'] = date('c', $data['last_user_activity']);
$data['database_size'] = format_bytes($data['database_size']);
diff --git a/config.default.php b/config.default.php
index 5d43d7d82..6ea4c7db6 100644
--- a/config.default.php
+++ b/config.default.php
@@ -3,7 +3,7 @@
# Do not modify this file, which defines default values,
# but instead edit `./data/config.php` after the install process is completed,
# or edit `./data/config.custom.php` before the install process.
-return array(
+return [
# Set to `development` to get additional error messages,
# or to `production` to get only the most important messages.
@@ -94,7 +94,7 @@ return array(
# Faster with higher values. Reduce for server with little memory or database issues.
'nb_parallel_refresh' => 10,
- 'limits' => array(
+ 'limits' => [
# Duration in seconds of the login cookie.
'cookie_duration' => FreshRSS_Auth::DEFAULT_COOKIE_DURATION,
@@ -125,11 +125,11 @@ return array(
# 0 for an unlimited number of accounts
# 1 is to not allow user registrations (1 is corresponding to the admin account)
'max_registrations' => 1,
- ),
+ ],
# Options used by cURL when making HTTP requests, e.g. when the SimplePie library retrieves feeds.
# https://php.net/manual/function.curl-setopt
- 'curl_options' => array(
+ 'curl_options' => [
# Options to disable SSL/TLS certificate check (e.g. for self-signed HTTPS)
//CURLOPT_SSL_VERIFYHOST => 0,
//CURLOPT_SSL_VERIFYPEER => false,
@@ -140,7 +140,7 @@ return array(
//CURLOPT_PROXYPORT => 8080,
//CURLOPT_PROXYAUTH => CURLAUTH_BASIC,
//CURLOPT_PROXYUSERPWD => 'user:password',
- ),
+ ],
'db' => [
@@ -181,7 +181,7 @@ return array(
#
# See https://phpmailer.github.io/PHPMailer/classes/PHPMailer-PHPMailer-PHPMailer.html#properties
'mailer' => 'mail', // 'mail' or 'smtp'
- 'smtp' => array(
+ 'smtp' => [
'hostname' => '', // the domain used in the Message-ID header
'host' => 'localhost', // the SMTP server address
'port' => 25,
@@ -191,7 +191,7 @@ return array(
'password' => '',
'secure' => '', // '', 'ssl' or 'tls'
'from' => 'root@localhost',
- ),
+ ],
# List of enabled FreshRSS extensions.
'extensions_enabled' => [
@@ -212,4 +212,4 @@ return array(
'127.0.0.0/8',
'::1/128',
]
-);
+];
diff --git a/docs/en/admins/05_Configuring_email_validation.md b/docs/en/admins/05_Configuring_email_validation.md
index aec6b8b75..2bbfeb6c3 100644
--- a/docs/en/admins/05_Configuring_email_validation.md
+++ b/docs/en/admins/05_Configuring_email_validation.md
@@ -36,7 +36,7 @@ PHPMailer documentation](http://phpmailer.github.io/PHPMailer/classes/PHPMailer.
```php
'mailer' => 'smtp', // instead of 'mail'
- 'smtp' => array(
+ 'smtp' => [
'hostname' => 'example.net',
'host' => 'smtp.example.net', // URL to your smtp server
'port' => 465,
@@ -46,7 +46,7 @@ PHPMailer documentation](http://phpmailer.github.io/PHPMailer/classes/PHPMailer.
'password' => 'yoursecretpassword',
'secure' => 'ssl', // '', 'ssl' or 'tls'
'from' => 'alice@example.net',
- ),
+ ],
```
## Check your SMTP server is correctly configured
diff --git a/docs/en/developers/05_Release_new_version.md b/docs/en/developers/05_Release_new_version.md
index ef69084ae..b6a22982d 100644
--- a/docs/en/developers/05_Release_new_version.md
+++ b/docs/en/developers/05_Release_new_version.md
@@ -53,7 +53,7 @@ Here’s an example of a `versions.php` file:
```php
<?php
-return array(
+return [
// STABLE
'0.8.0' => '1.0.0',
'0.8.1' => '1.0.0',
@@ -62,7 +62,7 @@ return array(
'1.1.2-dev' => 'dev',
'1.1.3-dev' => 'dev',
'1.1.4-dev' => 'dev',
-);
+];
```
And here’s how this table works:
diff --git a/docs/fr/developers/05_Release_new_version.md b/docs/fr/developers/05_Release_new_version.md
index c9c4e9389..83b164ce8 100644
--- a/docs/fr/developers/05_Release_new_version.md
+++ b/docs/fr/developers/05_Release_new_version.md
@@ -83,7 +83,7 @@ Voici un exemple de fichier `versions.php` :
```php
<?php
-return array(
+return [
// STABLE
'0.8.0' => '1.0.0',
'0.8.1' => '1.0.0',
@@ -92,7 +92,7 @@ return array(
'1.1.2-dev' => 'dev',
'1.1.3-dev' => 'dev',
'1.1.4-dev' => 'dev',
-);
+];
```
Et voici comment fonctionne cette table :
diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php
index 40a5851a9..b2742e249 100644
--- a/lib/Minz/Configuration.php
+++ b/lib/Minz/Configuration.php
@@ -18,7 +18,7 @@ class Minz_Configuration {
* The list of configurations.
* @var array<string,static>
*/
- private static array $config_list = array();
+ private static array $config_list = [];
/**
* Add a new configuration to the list of configuration.
@@ -132,7 +132,7 @@ class Minz_Configuration {
* @param Minz_ConfigurationSetterInterface|null $configuration_setter the setter to call when modifying data.
*/
public function _configurationSetter(?Minz_ConfigurationSetterInterface $configuration_setter): void {
- if (is_callable(array($configuration_setter, 'handle'))) {
+ if (is_callable([$configuration_setter, 'handle'])) {
$this->configuration_setter = $configuration_setter;
}
}
diff --git a/lib/Minz/ExtensionManager.php b/lib/Minz/ExtensionManager.php
index 976dddb82..90f005d29 100644
--- a/lib/Minz/ExtensionManager.php
+++ b/lib/Minz/ExtensionManager.php
@@ -22,74 +22,74 @@ final class Minz_ExtensionManager {
* @var array<string,array{'list':array<callable>,'signature':'NoneToNone'|'NoneToString'|'OneToOne'|'PassArguments'}>
*/
private static array $hook_list = [
- 'check_url_before_add' => array( // function($url) -> Url | null
- 'list' => array(),
+ 'check_url_before_add' => [ // function($url) -> Url | null
+ 'list' => [],
'signature' => 'OneToOne',
- ),
+ ],
'entries_favorite' => [ // function(array $ids, bool $is_favorite): void
'list' => [],
'signature' => 'PassArguments',
],
- 'entry_auto_read' => array( // function(FreshRSS_Entry $entry, string $why): void
- 'list' => array(),
+ 'entry_auto_read' => [ // function(FreshRSS_Entry $entry, string $why): void
+ 'list' => [],
'signature' => 'PassArguments',
- ),
- 'entry_auto_unread' => array( // function(FreshRSS_Entry $entry, string $why): void
- 'list' => array(),
+ ],
+ 'entry_auto_unread' => [ // function(FreshRSS_Entry $entry, string $why): void
+ 'list' => [],
'signature' => 'PassArguments',
- ),
- 'entry_before_display' => array( // function($entry) -> Entry | null
- 'list' => array(),
+ ],
+ 'entry_before_display' => [ // function($entry) -> Entry | null
+ 'list' => [],
'signature' => 'OneToOne',
- ),
- 'entry_before_insert' => array( // function($entry) -> Entry | null
- 'list' => array(),
+ ],
+ 'entry_before_insert' => [ // function($entry) -> Entry | null
+ 'list' => [],
'signature' => 'OneToOne',
- ),
- 'feed_before_actualize' => array( // function($feed) -> Feed | null
- 'list' => array(),
+ ],
+ 'feed_before_actualize' => [ // function($feed) -> Feed | null
+ 'list' => [],
'signature' => 'OneToOne',
- ),
- 'feed_before_insert' => array( // function($feed) -> Feed | null
- 'list' => array(),
+ ],
+ 'feed_before_insert' => [ // function($feed) -> Feed | null
+ 'list' => [],
'signature' => 'OneToOne',
- ),
- 'freshrss_init' => array( // function() -> none
- 'list' => array(),
+ ],
+ 'freshrss_init' => [ // function() -> none
+ 'list' => [],
'signature' => 'NoneToNone',
- ),
- 'freshrss_user_maintenance' => array( // function() -> none
- 'list' => array(),
+ ],
+ 'freshrss_user_maintenance' => [ // function() -> none
+ 'list' => [],
'signature' => 'NoneToNone',
- ),
- 'js_vars' => array( // function($vars = array) -> array | null
- 'list' => array(),
+ ],
+ 'js_vars' => [ // function($vars = array) -> array | null
+ 'list' => [],
'signature' => 'OneToOne',
- ),
- 'menu_admin_entry' => array( // function() -> string
- 'list' => array(),
+ ],
+ 'menu_admin_entry' => [ // function() -> string
+ 'list' => [],
'signature' => 'NoneToString',
- ),
- 'menu_configuration_entry' => array( // function() -> string
- 'list' => array(),
+ ],
+ 'menu_configuration_entry' => [ // function() -> string
+ 'list' => [],
'signature' => 'NoneToString',
- ),
- 'menu_other_entry' => array( // function() -> string
- 'list' => array(),
+ ],
+ 'menu_other_entry' => [ // function() -> string
+ 'list' => [],
'signature' => 'NoneToString',
- ),
- 'nav_menu' => array( // function() -> string
- 'list' => array(),
+ ],
+ 'nav_menu' => [ // function() -> string
+ 'list' => [],
'signature' => 'NoneToString',
- ),
- 'nav_reading_modes' => array( // function($readingModes = array) -> array | null
- 'list' => array(),
+ ],
+ 'nav_reading_modes' => [ // function($readingModes = array) -> array | null
+ 'list' => [],
'signature' => 'OneToOne',
- ),
- 'post_update' => array( // function(none) -> none
- 'list' => array(),
+ ],
+ 'post_update' => [ // function(none) -> none
+ 'list' => [],
'signature' => 'NoneToNone',
- ),
+ ],
'simplepie_after_init' => [ // function(\SimplePie\SimplePie $simplePie, FreshRSS_Feed $feed, bool $result): void
'list' => [],
'signature' => 'PassArguments',
@@ -187,7 +187,7 @@ final class Minz_ExtensionManager {
* @return bool true if the array is valid, false else.
*/
private static function isValidMetadata(array $meta): bool {
- $valid_chars = array('_');
+ $valid_chars = ['_'];
return !(empty($meta['name']) || empty($meta['entrypoint']) || !ctype_alnum(str_replace($valid_chars, '', $meta['entrypoint'])));
}
diff --git a/lib/Minz/ModelArray.php b/lib/Minz/ModelArray.php
index f12e23567..5a1d286cd 100644
--- a/lib/Minz/ModelArray.php
+++ b/lib/Minz/ModelArray.php
@@ -41,7 +41,7 @@ class Minz_ModelArray {
if ($data === false) {
throw new Minz_PermissionDeniedException($this->filename);
} elseif (!is_array($data)) {
- $data = array();
+ $data = [];
}
return $data;
}
diff --git a/lib/Minz/PdoPgsql.php b/lib/Minz/PdoPgsql.php
index d075c396f..a43d7addf 100644
--- a/lib/Minz/PdoPgsql.php
+++ b/lib/Minz/PdoPgsql.php
@@ -24,6 +24,6 @@ class Minz_PdoPgsql extends Minz_Pdo {
#[\Override]
protected function preSql(string $statement): string {
$statement = parent::preSql($statement);
- return str_replace(array('`', ' LIKE '), array('"', ' ILIKE '), $statement);
+ return str_replace(['`', ' LIKE '], ['"', ' ILIKE '], $statement);
}
}
diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php
index b4d4549a9..bddb5a276 100644
--- a/lib/Minz/Request.php
+++ b/lib/Minz/Request.php
@@ -490,6 +490,6 @@ class Minz_Request {
if (preg_match_all('/(^|,)\s*(?P<lang>[^;,]+)/', $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '', $matches) > 0) {
return $matches['lang'];
}
- return array('en');
+ return ['en'];
}
}
diff --git a/lib/Minz/Session.php b/lib/Minz/Session.php
index c08ad688b..9977e62f6 100644
--- a/lib/Minz/Session.php
+++ b/lib/Minz/Session.php
@@ -164,7 +164,7 @@ class Minz_Session {
if (!self::$volatile) {
session_destroy();
}
- $_SESSION = array();
+ $_SESSION = [];
if (!$force) {
self::_param('language', $language);
diff --git a/lib/Minz/Translate.php b/lib/Minz/Translate.php
index a8dc889ee..08b3c91e8 100644
--- a/lib/Minz/Translate.php
+++ b/lib/Minz/Translate.php
@@ -40,8 +40,8 @@ class Minz_Translate {
*/
public static function init(string $lang_name = ''): void {
self::$lang_name = $lang_name;
- self::$lang_files = array();
- self::$translates = array();
+ self::$lang_files = [];
+ self::$translates = [];
self::registerPath(APP_PATH . '/i18n');
foreach (self::$path_list as $path) {
self::loadLang($path);
@@ -54,8 +54,8 @@ class Minz_Translate {
*/
public static function reset(string $lang_name): void {
self::$lang_name = $lang_name;
- self::$lang_files = array();
- self::$translates = array();
+ self::$lang_files = [];
+ self::$translates = [];
foreach (self::$path_list as $path) {
self::loadLang($path);
}
@@ -66,7 +66,7 @@ class Minz_Translate {
* @return array<string> containing langs found in different registered paths.
*/
public static function availableLanguages(): array {
- $list_langs = array();
+ $list_langs = [];
self::registerPath(APP_PATH . '/i18n');
@@ -75,7 +75,7 @@ class Minz_Translate {
if (is_array($scan)) {
$path_langs = array_values(array_diff(
$scan,
- array('..', '.')
+ ['..', '.']
));
$list_langs = array_merge($list_langs, $path_langs);
}
@@ -146,7 +146,7 @@ class Minz_Translate {
foreach ($list_i18n_files as $i18n_filename) {
$i18n_key = basename($i18n_filename, '.php');
if (!isset(self::$lang_files[$i18n_key])) {
- self::$lang_files[$i18n_key] = array();
+ self::$lang_files[$i18n_key] = [];
}
self::$lang_files[$i18n_key][] = $lang_path . '/' . $i18n_filename;
self::$translates[$i18n_key] = null;
@@ -164,7 +164,7 @@ class Minz_Translate {
return false;
}
- self::$translates[$key] = array();
+ self::$translates[$key] = [];
foreach (self::$lang_files[$key] as $lang_pathname) {
$i18n_array = include($lang_pathname);
diff --git a/lib/favicons.php b/lib/favicons.php
index be83b8066..5df3682b8 100644
--- a/lib/favicons.php
+++ b/lib/favicons.php
@@ -103,7 +103,7 @@ function searchFavicon(string &$url): string {
}
$iri = $href->get_iri();
- $favicon = downloadHttp($iri, array(CURLOPT_REFERER => $url));
+ $favicon = downloadHttp($iri, [CURLOPT_REFERER => $url]);
if (isImgMime($favicon)) {
return $favicon;
}
@@ -122,9 +122,7 @@ function download_favicon(string $url, string $dest): bool {
}
if ($favicon == '') {
$link = $rootUrl . 'favicon.ico';
- $favicon = downloadHttp($link, array(
- CURLOPT_REFERER => $url,
- ));
+ $favicon = downloadHttp($link, [CURLOPT_REFERER => $url]);
if (!isImgMime($favicon)) {
$favicon = '';
}
diff --git a/lib/lib_date.php b/lib/lib_date.php
index 201d548ad..9d4bcaa07 100644
--- a/lib/lib_date.php
+++ b/lib/lib_date.php
@@ -67,7 +67,7 @@ function _dateCeiling(string $isoDate): string {
/** @phpstan-return ($isoDate is null ? null : ($isoDate is '' ? null : string)) */
function _noDelimit(?string $isoDate): ?string {
- return $isoDate === null || $isoDate === '' ? null : str_replace(array('-', ':'), '', $isoDate); //FIXME: Bug with negative time zone
+ return $isoDate === null || $isoDate === '' ? null : str_replace(['-', ':'], '', $isoDate); //FIXME: Bug with negative time zone
}
function _dateRelative(?string $d1, ?string $d2): ?string {
@@ -139,5 +139,5 @@ function parseDateInterval(string $dateInterval): array {
$min = false;
}
}
- return array($min, $max);
+ return [$min, $max];
}
diff --git a/lib/lib_install.php b/lib/lib_install.php
index d8ccd7624..e78de565b 100644
--- a/lib/lib_install.php
+++ b/lib/lib_install.php
@@ -47,7 +47,7 @@ function checkRequirements(string $dbType = ''): array {
$users = is_dir(USERS_PATH) && touch(USERS_PATH . '/index.html');
$favicons = is_dir(DATA_PATH) && touch(DATA_PATH . '/favicons/index.html');
- return array(
+ return [
'php' => $php ? 'ok' : 'ko',
'curl' => $curl ? 'ok' : 'ko',
'pdo-mysql' => $pdo_mysql ? 'ok' : 'ko',
@@ -68,8 +68,8 @@ function checkRequirements(string $dbType = ''): array {
'favicons' => $favicons ? 'ok' : 'ko',
'message' => $message ?: '',
'all' => $php && $curl && $pdo && $pcre && $ctype && $dom && $xml &&
- $data && $cache && $tmp && $users && $favicons && $message == '' ? 'ok' : 'ko'
- );
+ $data && $cache && $tmp && $users && $favicons && $message == '' ? 'ok' : 'ko',
+ ];
}
function generateSalt(): string {
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index 32139d8c8..8eb89c578 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -178,14 +178,14 @@ function escapeToUnicodeAlternative(string $text, bool $extended = true): string
$text = htmlspecialchars_decode($text, ENT_QUOTES);
//Problematic characters
- $problem = array('&', '<', '>');
+ $problem = ['&', '<', '>'];
//Use their fullwidth Unicode form instead:
- $replace = array('&', '<', '>');
+ $replace = ['&', '<', '>'];
// https://raw.githubusercontent.com/mihaip/google-reader-api/master/wiki/StreamId.wiki
if ($extended) {
- $problem += array("'", '"', '^', '?', '\\', '/', ',', ';');
- $replace += array("’", '"', '^', '?', '\', '/', ',', ';');
+ $problem += ["'", '"', '^', '?', '\\', '/', ',', ';'];
+ $replace += ["’", '"', '^', '?', '\', '/', ',', ';'];
}
return trim(str_replace($problem, $replace, $text));
@@ -202,10 +202,10 @@ function format_number($n, int $precision = 0): string {
function format_bytes(int $bytes, int $precision = 2, string $system = 'IEC'): string {
if ($system === 'IEC') {
$base = 1024;
- $units = array('B', 'KiB', 'MiB', 'GiB', 'TiB');
+ $units = ['B', 'KiB', 'MiB', 'GiB', 'TiB'];
} elseif ($system === 'SI') {
$base = 1000;
- $units = array('B', 'KB', 'MB', 'GB', 'TB');
+ $units = ['B', 'KB', 'MB', 'GB', 'TB'];
} else {
return format_number($bytes, $precision);
}
@@ -506,7 +506,7 @@ function httpGet(string $url, string $cachePath, string $type = 'html', array $a
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
- CURLOPT_HTTPHEADER => array('Accept: ' . $accept),
+ CURLOPT_HTTPHEADER => ['Accept: ' . $accept],
CURLOPT_USERAGENT => FRESHRSS_USERAGENT,
CURLOPT_CONNECTTIMEOUT => $feed_timeout > 0 ? $feed_timeout : $limits['timeout'],
CURLOPT_TIMEOUT => $feed_timeout > 0 ? $feed_timeout : $limits['timeout'],
@@ -609,7 +609,7 @@ function invalidateHttpCache(string $username = ''): bool {
* @return array<string>
*/
function listUsers(): array {
- $final_list = array();
+ $final_list = [];
$base_path = join_path(DATA_PATH, 'users');
$dir_list = array_values(array_diff(
scandir($base_path) ?: [],
@@ -784,7 +784,7 @@ function check_install_php(): array {
$pdo_mysql = extension_loaded('pdo_mysql');
$pdo_pgsql = extension_loaded('pdo_pgsql');
$pdo_sqlite = extension_loaded('pdo_sqlite');
- return array(
+ return [
'php' => version_compare(PHP_VERSION, FRESHRSS_MIN_PHP_VERSION) >= 0,
'curl' => extension_loaded('curl'),
'pdo' => $pdo_mysql || $pdo_sqlite || $pdo_pgsql,
@@ -795,7 +795,7 @@ function check_install_php(): array {
'json' => extension_loaded('json'),
'mbstring' => extension_loaded('mbstring'),
'zip' => extension_loaded('zip'),
- );
+ ];
}
/**
@@ -818,7 +818,7 @@ function check_install_files(): array {
* @return array<string,bool> of tested values.
*/
function check_install_database(): array {
- $status = array(
+ $status = [
'connection' => true,
'tables' => false,
'categories' => false,
@@ -827,7 +827,7 @@ function check_install_database(): array {
'entrytmp' => false,
'tag' => false,
'entrytag' => false,
- );
+ ];
try {
$dbDAO = FreshRSS_Factory::createDatabaseDAO();
@@ -876,7 +876,7 @@ function recursive_unlink(string $dir): bool {
* @return array<int,array<string,string|int>> without queries where $get is appearing.
*/
function remove_query_by_get(string $get, array $queries): array {
- $final_queries = array();
+ $final_queries = [];
foreach ($queries as $key => $query) {
if (empty($query['get']) || $query['get'] !== $get) {
$final_queries[$key] = $query;
diff --git a/p/api/fever.php b/p/api/fever.php
index 5ddfba269..8748882e5 100644
--- a/p/api/fever.php
+++ b/p/api/fever.php
@@ -39,7 +39,7 @@ function debugInfo(): string {
} else { //nginx http://php.net/getallheaders#84262
$ALL_HEADERS = [];
foreach ($_SERVER as $name => $value) {
- if (substr($name, 0, 5) === 'HTTP_') {
+ if (str_starts_with($name, 'HTTP_')) {
$ALL_HEADERS[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
diff --git a/p/api/greader.php b/p/api/greader.php
index ecdb9f0cf..218db7561 100644
--- a/p/api/greader.php
+++ b/p/api/greader.php
@@ -75,11 +75,11 @@ function multiplePosts(string $name): array {
//https://bugs.php.net/bug.php?id=51633
global $ORIGINAL_INPUT;
$inputs = explode('&', $ORIGINAL_INPUT);
- $result = array();
+ $result = [];
$prefix = $name . '=';
$prefixLength = strlen($prefix);
foreach ($inputs as $input) {
- if (strpos($input, $prefix) === 0) {
+ if (str_starts_with($input, $prefix)) {
$result[] = urldecode(substr($input, $prefixLength));
}
}
@@ -90,9 +90,9 @@ function debugInfo(): string {
if (function_exists('getallheaders')) {
$ALL_HEADERS = getallheaders();
} else { //nginx http://php.net/getallheaders#84262
- $ALL_HEADERS = array();
+ $ALL_HEADERS = [];
foreach ($_SERVER as $name => $value) {
- if (substr($name, 0, 5) === 'HTTP_') {
+ if (str_starts_with($name, 'HTTP_')) {
$ALL_HEADERS[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
@@ -266,44 +266,43 @@ final class GReaderAPI {
self::unauthorized();
}
$user = Minz_User::name();
- exit(json_encode(array(
- 'userId' => $user,
- 'userName' => $user,
- 'userProfileId' => $user,
- 'userEmail' => FreshRSS_Context::userConf()->mail_login,
- ), JSON_OPTIONS));
+ exit(json_encode([
+ 'userId' => $user,
+ 'userName' => $user,
+ 'userProfileId' => $user,
+ 'userEmail' => FreshRSS_Context::userConf()->mail_login,
+ ], JSON_OPTIONS));
}
private static function tagList(): never {
header('Content-Type: application/json; charset=UTF-8');
- $tags = array(
- array('id' => 'user/-/state/com.google/starred'),
- //array('id' => 'user/-/state/com.google/broadcast', 'sortid' => '2'),
- );
-
+ $tags = [
+ ['id' => 'user/-/state/com.google/starred'],
+ // ['id' => 'user/-/state/com.google/broadcast', 'sortid' => '2']
+ ];
$categoryDAO = FreshRSS_Factory::createCategoryDao();
$categories = $categoryDAO->listCategories(true, false) ?: [];
foreach ($categories as $cat) {
- $tags[] = array(
+ $tags[] = [
'id' => 'user/-/label/' . htmlspecialchars_decode($cat->name(), ENT_QUOTES),
//'sortid' => $cat->name(),
'type' => 'folder', //Inoreader
- );
+ ];
}
$tagDAO = FreshRSS_Factory::createTagDao();
$labels = $tagDAO->listTags(true) ?: [];
foreach ($labels as $label) {
- $tags[] = array(
+ $tags[] = [
'id' => 'user/-/label/' . htmlspecialchars_decode($label->name(), ENT_QUOTES),
//'sortid' => $label->name(),
'type' => 'tag', //Inoreader
'unread_count' => $label->nbUnread(), //Inoreader
- );
+ ];
}
- echo json_encode(array('tags' => $tags), JSON_OPTIONS), "\n";
+ echo json_encode(['tags' => $tags], JSON_OPTIONS), "\n";
exit();
}
@@ -338,7 +337,7 @@ final class GReaderAPI {
$salt = FreshRSS_Context::systemConf()->salt;
$faviconsUrl = Minz_Url::display('/f.php?', '', true);
$faviconsUrl = str_replace('/api/greader.php/reader/api/0/subscription', '', $faviconsUrl); //Security if base_url is not set properly
- $subscriptions = array();
+ $subscriptions = [];
$categoryDAO = FreshRSS_Factory::createCategoryDao();
foreach ($categoryDAO->listCategories(true, true) ?: [] as $cat) {
@@ -361,7 +360,7 @@ final class GReaderAPI {
}
}
- echo json_encode(array('subscriptions' => $subscriptions), JSON_OPTIONS), "\n";
+ echo json_encode(['subscriptions' => $subscriptions], JSON_OPTIONS), "\n";
exit();
}
@@ -412,7 +411,7 @@ final class GReaderAPI {
$feedDAO = FreshRSS_Factory::createFeedDao();
for ($i = count($streamNames) - 1; $i >= 0; $i--) {
$streamUrl = $streamNames[$i]; //feed/http://example.net/sample.xml ; feed/338
- if (strpos($streamUrl, 'feed/') === 0) {
+ if (str_starts_with($streamUrl, 'feed/')) {
$streamUrl = '' . preg_replace('%^(feed/)+%', '', $streamUrl);
$feedId = 0;
if (is_numeric($streamUrl)) {
@@ -470,18 +469,18 @@ final class GReaderAPI {
$url = substr($url, 5);
}
$feed = FreshRSS_feed_Controller::addFeed($url);
- exit(json_encode(array(
+ exit(json_encode([
'numResults' => 1,
'query' => $feed->url(),
'streamId' => 'feed/' . $feed->id(),
'streamName' => $feed->name(),
- ), JSON_OPTIONS));
+ ], JSON_OPTIONS));
} catch (Exception $e) {
Minz_Log::error('quickadd error: ' . $e->getMessage(), API_LOG);
- die(json_encode(array(
+ die(json_encode([
'numResults' => 0,
'error' => $e->getMessage(),
- ), JSON_OPTIONS));
+ ], JSON_OPTIONS));
}
}
@@ -495,25 +494,25 @@ final class GReaderAPI {
$categoryDAO = FreshRSS_Factory::createCategoryDao();
$feedDAO = FreshRSS_Factory::createFeedDao();
$feedsNewestItemUsec = $feedDAO->listFeedsNewestItemUsec();
-
+ $unreadcounts = [];
foreach ($categoryDAO->listCategories(true, true) ?: [] as $cat) {
$catLastUpdate = 0;
foreach ($cat->feeds() as $feed) {
$lastUpdate = $feedsNewestItemUsec['f_' . $feed->id()] ?? 0;
- $unreadcounts[] = array(
+ $unreadcounts[] = [
'id' => 'feed/' . $feed->id(),
'count' => $feed->nbNotRead(),
'newestItemTimestampUsec' => '' . $lastUpdate,
- );
+ ];
if ($catLastUpdate < $lastUpdate) {
$catLastUpdate = $lastUpdate;
}
}
- $unreadcounts[] = array(
+ $unreadcounts[] = [
'id' => 'user/-/label/' . htmlspecialchars_decode($cat->name(), ENT_QUOTES),
'count' => $cat->nbNotRead(),
'newestItemTimestampUsec' => '' . $catLastUpdate,
- );
+ ];
$totalUnreads += $cat->nbNotRead();
if ($totalLastUpdate < $catLastUpdate) {
$totalLastUpdate = $catLastUpdate;
@@ -524,23 +523,23 @@ final class GReaderAPI {
$tagsNewestItemUsec = $tagDAO->listTagsNewestItemUsec();
foreach ($tagDAO->listTags(true) ?: [] as $label) {
$lastUpdate = $tagsNewestItemUsec['t_' . $label->id()] ?? 0;
- $unreadcounts[] = array(
+ $unreadcounts[] = [
'id' => 'user/-/label/' . htmlspecialchars_decode($label->name(), ENT_QUOTES),
'count' => $label->nbUnread(),
'newestItemTimestampUsec' => '' . $lastUpdate,
- );
+ ];
}
- $unreadcounts[] = array(
+ $unreadcounts[] = [
'id' => 'user/-/state/com.google/reading-list',
'count' => $totalUnreads,
'newestItemTimestampUsec' => '' . $totalLastUpdate,
- );
+ ];
- echo json_encode(array(
+ echo json_encode([
'max' => $totalUnreads,
'unreadcounts' => $unreadcounts,
- ), JSON_OPTIONS), "\n";
+ ], JSON_OPTIONS), "\n";
exit();
}
@@ -550,7 +549,7 @@ final class GReaderAPI {
*/
private static function entriesToArray(array $entries): array {
if (empty($entries)) {
- return array();
+ return [];
}
$catDAO = FreshRSS_Factory::createCategoryDao();
$categories = $catDAO->listCategories(true) ?: [];
@@ -558,7 +557,7 @@ final class GReaderAPI {
$tagDAO = FreshRSS_Factory::createTagDao();
$entryIdsTagNames = $tagDAO->getEntryIdsTagNames($entries);
- $items = array();
+ $items = [];
foreach ($entries as $item) {
/** @var FreshRSS_Entry $entry */
$entry = Minz_ExtensionManager::callHook('entry_before_display', $item);
@@ -614,20 +613,12 @@ final class GReaderAPI {
}
$streamId = (int)$streamId;
- switch ($filter_target) {
- case 'user/-/state/com.google/read':
- $state = FreshRSS_Entry::STATE_READ;
- break;
- case 'user/-/state/com.google/unread':
- $state = FreshRSS_Entry::STATE_NOT_READ;
- break;
- case 'user/-/state/com.google/starred':
- $state = FreshRSS_Entry::STATE_FAVORITE;
- break;
- default:
- $state = FreshRSS_Entry::STATE_ALL;
- break;
- }
+ $state = match ($filter_target) {
+ 'user/-/state/com.google/read' => FreshRSS_Entry::STATE_READ,
+ 'user/-/state/com.google/unread' => FreshRSS_Entry::STATE_NOT_READ,
+ 'user/-/state/com.google/starred' => FreshRSS_Entry::STATE_FAVORITE,
+ default => FreshRSS_Entry::STATE_ALL,
+ };
switch ($exclude_target) {
case 'user/-/state/com.google/read':
@@ -642,18 +633,18 @@ final class GReaderAPI {
}
$searches = new FreshRSS_BooleanSearch('');
- if ($start_time != '') {
+ if ($start_time !== 0) {
$search = new FreshRSS_Search('');
$search->setMinDate($start_time);
$searches->add($search);
}
- if ($stop_time != '') {
+ if ($stop_time !== 0) {
$search = new FreshRSS_Search('');
$search->setMaxDate($stop_time);
$searches->add($search);
}
- return array($type, $streamId, $state, $searches);
+ return [$type, $streamId, $state, $searches];
}
private static function streamContents(string $path, string $include_target, int $start_time, int $stop_time, int $count,
@@ -662,21 +653,13 @@ final class GReaderAPI {
//http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#feed
header('Content-Type: application/json; charset=UTF-8');
- switch ($path) {
- case 'starred':
- $type = 's';
- break;
- case 'feed':
- $type = 'f';
- break;
- case 'label':
- $type = 'c';
- break;
- case 'reading-list':
- default:
- $type = 'A';
- break;
- }
+ $type = match ($path) {
+ 'starred' => 's',
+ 'feed' => 'f',
+ 'label' => 'c',
+ 'reading-list' => 'A',
+ default => 'A',
+ };
[$type, $include_target, $state, $searches] =
self::streamContentsFilters($type, $include_target, $filter_target, $exclude_target, $start_time, $stop_time);
@@ -696,11 +679,11 @@ final class GReaderAPI {
$count--;
}
- $response = array(
+ $response = [
'id' => 'user/-/state/com.google/reading-list',
'updated' => time(),
'items' => $items,
- );
+ ];
if (count($entries) >= $count) {
$entry = end($entries);
if ($entry != false) {
@@ -723,10 +706,10 @@ final class GReaderAPI {
$type = 'A';
} elseif ($streamId === 'user/-/state/com.google/starred') {
$type = 's';
- } elseif (strpos($streamId, 'feed/') === 0) {
+ } elseif (str_starts_with($streamId, 'feed/')) {
$type = 'f';
$streamId = substr($streamId, 5);
- } elseif (strpos($streamId, 'user/-/label/') === 0) {
+ } elseif (str_starts_with($streamId, 'user/-/label/')) {
$type = 'c';
$streamId = substr($streamId, 13);
}
@@ -751,16 +734,16 @@ final class GReaderAPI {
if (empty($ids) && isset($_GET['client']) && $_GET['client'] === 'newsplus') {
$ids = [ 0 ]; //For News+ bug https://github.com/noinnion/newsplus/issues/84#issuecomment-57834632
}
- $itemRefs = array();
+ $itemRefs = [];
foreach ($ids as $entryId) {
- $itemRefs[] = array(
+ $itemRefs[] = [
'id' => '' . $entryId, //64-bit decimal
- );
+ ];
}
- $response = array(
+ $response = [
'itemRefs' => $itemRefs,
- );
+ ];
if (count($ids) >= $count) {
$entryId = end($ids);
if ($entryId != false) {
@@ -792,11 +775,11 @@ final class GReaderAPI {
$items = self::entriesToArray($entries);
- $response = array(
+ $response = [
'id' => 'user/-/state/com.google/reading-list',
'updated' => time(),
'items' => $items,
- );
+ ];
unset($entries, $entryDAO, $items);
gc_collect_cycles();
echoJson($response, 2); // $optimisationDepth=2 as we are interested in being memory efficient for {"items":[...]}
@@ -832,12 +815,12 @@ final class GReaderAPI {
break;*/
default:
$tagName = '';
- if (strpos($a, 'user/-/label/') === 0) {
+ if (str_starts_with($a, 'user/-/label/')) {
$tagName = substr($a, 13);
} else {
$user = Minz_User::name() ?? '';
$prefix = 'user/' . $user . '/label/';
- if (strpos($a, $prefix) === 0) {
+ if (str_starts_with($a, $prefix)) {
$tagName = substr($a, strlen($prefix));
}
}
@@ -845,7 +828,7 @@ final class GReaderAPI {
$tagName = htmlspecialchars($tagName, ENT_COMPAT, 'UTF-8');
$tag = $tagDAO->searchByName($tagName);
if ($tag == null) {
- $tagDAO->addTag(array('name' => $tagName));
+ $tagDAO->addTag(['name' => $tagName]);
$tag = $tagDAO->searchByName($tagName);
}
if ($tag != null) {
@@ -864,7 +847,7 @@ final class GReaderAPI {
$entryDAO->markFavorite($e_ids, false);
break;
default:
- if (strpos($r, 'user/-/label/') === 0) {
+ if (str_starts_with($r, 'user/-/label/')) {
$tagName = substr($r, 13);
$tagName = htmlspecialchars($tagName, ENT_COMPAT, 'UTF-8');
$tag = $tagDAO->searchByName($tagName);
@@ -881,8 +864,7 @@ final class GReaderAPI {
}
private static function renameTag(string $s, string $dest): never {
- if ($s != '' && strpos($s, 'user/-/label/') === 0 &&
- $dest != '' && strpos($dest, 'user/-/label/') === 0) {
+ if (str_starts_with($s, 'user/-/label/') && str_starts_with($dest, 'user/-/label/')) {
$s = substr($s, 13);
$s = htmlspecialchars($s, ENT_COMPAT, 'UTF-8');
$dest = substr($dest, 13);
@@ -908,7 +890,7 @@ final class GReaderAPI {
}
private static function disableTag(string $s): never {
- if ($s != '' && strpos($s, 'user/-/label/') === 0) {
+ if (str_starts_with($s, 'user/-/label/')) {
$s = substr($s, 13);
$s = htmlspecialchars($s, ENT_COMPAT, 'UTF-8');
$categoryDAO = FreshRSS_Factory::createCategoryDao();
@@ -937,14 +919,14 @@ final class GReaderAPI {
*/
private static function markAllAsRead(string $streamId, string $olderThanId): never {
$entryDAO = FreshRSS_Factory::createEntryDao();
- if (strpos($streamId, 'feed/') === 0) {
+ if (str_starts_with($streamId, 'feed/')) {
$f_id = basename($streamId);
if (!is_numeric($f_id)) {
self::badRequest();
}
$f_id = (int)$f_id;
$entryDAO->markReadFeed($f_id, $olderThanId);
- } elseif (strpos($streamId, 'user/-/label/') === 0) {
+ } elseif (str_starts_with($streamId, 'user/-/label/')) {
$c_name = substr($streamId, 13);
$c_name = htmlspecialchars($c_name, ENT_COMPAT, 'UTF-8');
$categoryDAO = FreshRSS_Factory::createCategoryDao();
@@ -1033,27 +1015,32 @@ final class GReaderAPI {
$timestamp = isset($_GET['ck']) ? (int)$_GET['ck'] : 0; //ck=[unix timestamp] : Use the current Unix time here, helps Google with caching.
switch ($pathInfos[4]) {
case 'stream':
- /* xt=[exclude target] : Used to exclude certain items from the feed.
- * For example, using xt=user/-/state/com.google/read will exclude items
- * that the current user has marked as read, or xt=feed/[feedurl] will
- * exclude items from a particular feed (obviously not useful in this
- * request, but xt appears in other listing requests). */
+ /**
+ * xt=[exclude target]: Used to exclude certain items from the feed.
+ * For example, using xt=user/-/state/com.google/read will exclude items
+ * that the current user has marked as read, or xt=feed/[feedurl] will
+ * exclude items from a particular feed (obviously not useful in this request,
+ * but xt appears in other listing requests).
+ */
$exclude_target = $_GET['xt'] ?? '';
$filter_target = $_GET['it'] ?? '';
//n=[integer] : The maximum number of results to return.
$count = isset($_GET['n']) ? (int)$_GET['n'] : 20;
//r=[d|n|o] : Sort order of item results. d or n gives items in descending date order, o in ascending order.
$order = $_GET['r'] ?? 'd';
- /* ot=[unix timestamp] : The time from which you want to retrieve
- * items. Only items that have been crawled by Google Reader after
- * this time will be returned. */
+ /**
+ * ot=[unix timestamp] : The time from which you want to retrieve items.
+ * Only items that have been crawled by Google Reader after this time will be returned.
+ */
$start_time = isset($_GET['ot']) ? (int)$_GET['ot'] : 0;
$stop_time = isset($_GET['nt']) ? (int)$_GET['nt'] : 0;
- /* Continuation token. If a StreamContents response does not represent
- * all items in a timestamp range, it will have a continuation attribute.
- * The same request can be re-issued with the value of that attribute put
- * in this parameter to get more items */
- $continuation = isset($_GET['c']) ? trim($_GET['c']) : '';
+ /**
+ * Continuation token. If a StreamContents response does not represent
+ * all items in a timestamp range, it will have a continuation attribute.
+ * The same request can be re-issued with the value of that attribute put
+ * in this parameter to get more items
+ */
+ $continuation = isset($_GET['c']) ? trim((string)$_GET['c']) : '';
if (!ctype_digit($continuation)) {
$continuation = '';
}
@@ -1137,11 +1124,11 @@ final class GReaderAPI {
case 'edit':
if (isset($_REQUEST['s'], $_REQUEST['ac'])) {
// StreamId to operate on. The parameter may be repeated to edit multiple subscriptions at once
- $streamNames = empty($_POST['s']) && isset($_GET['s']) ? array($_GET['s']) : multiplePosts('s');
+ $streamNames = empty($_POST['s']) && isset($_GET['s']) ? [$_GET['s']] : multiplePosts('s');
/* Title to use for the subscription. For the `subscribe` action,
* if not specified then the feed’s current title will be used. Can
* be used with the `edit` action to rename a subscription */
- $titles = empty($_POST['t']) && isset($_GET['t']) ? array($_GET['t']) : multiplePosts('t');
+ $titles = empty($_POST['t']) && isset($_GET['t']) ? [$_GET['t']] : multiplePosts('t');
// Action to perform on the given StreamId. Possible values are `subscribe`, `unsubscribe` and `edit`
$action = $_REQUEST['ac'];
// StreamId to add the subscription to (generally a user label)
diff --git a/p/api/pshb.php b/p/api/pshb.php
index 9d0b9fadc..f8903d385 100644
--- a/p/api/pshb.php
+++ b/p/api/pshb.php
@@ -17,7 +17,7 @@ if (!FreshRSS_Context::hasSystemConf()) {
}
FreshRSS_Context::systemConf()->auth_type = 'none'; // avoid necessity to be logged in (not saved!)
-//Minz_Log::debug(print_r(array('_SERVER' => $_SERVER, '_GET' => $_GET, '_POST' => $_POST, 'INPUT' => $ORIGINAL_INPUT), true), PSHB_LOG);
+// Minz_Log::debug(print_r(['_SERVER' => $_SERVER, '_GET' => $_GET, '_POST' => $_POST, 'INPUT' => $ORIGINAL_INPUT], true), PSHB_LOG);
$key = isset($_GET['k']) ? substr($_GET['k'], 0, 128) : '';
if (!ctype_xdigit($key)) {
diff --git a/p/api/query.php b/p/api/query.php
index 345a56788..00a04d083 100644
--- a/p/api/query.php
+++ b/p/api/query.php
@@ -118,7 +118,7 @@ try {
FreshRSS_Context::updateUsingRequest(false);
Minz_Request::_param('search', $userSearch->getRawInput()); // Restore user search
$view->entries = FreshRSS_index_Controller::listEntriesByContext();
-} catch (Minz_Exception $e) {
+} catch (Minz_Exception) {
Minz_Error::error(400, 'Bad user query!');
die();
}
diff --git a/p/ext.php b/p/ext.php
index 5d95107da..0a8c46546 100644
--- a/p/ext.php
+++ b/p/ext.php
@@ -48,7 +48,7 @@ function is_valid_path_extension(string $path, string $extensionPath, bool $isSt
$real_ext_path = str_replace('\\', '/', $real_ext_path);
$path = str_replace('\\', '/', $path);
- $in_ext_path = (substr($path, 0, strlen($real_ext_path)) === $real_ext_path);
+ $in_ext_path = (str_starts_with($path, $real_ext_path));
if (!$in_ext_path) {
return false;
}
@@ -93,8 +93,7 @@ function sendNotFoundResponse(): never {
die();
}
-if (!isset($_GET['f']) || !is_string($_GET['f']) ||
- !isset($_GET['t']) || !is_string($_GET['t'])) {
+if (!isset($_GET['f'], $_GET['t']) || !is_string($_GET['f']) || !is_string($_GET['t'])) {
sendBadRequestResponse('Query string is incomplete.');
}
diff --git a/p/f.php b/p/f.php
index 6514c1045..1efcb97e5 100644
--- a/p/f.php
+++ b/p/f.php
@@ -42,9 +42,9 @@ if ($ico_mtime == false || $ico_mtime < $txt_mtime || ($ico_mtime < time() - (mt
if ($ico_mtime == false) {
show_default_favicon(86400);
exit();
- } else {
- touch($ico);
}
+
+ touch($ico);
}
}
diff --git a/tests/app/Models/SearchTest.php b/tests/app/Models/SearchTest.php
index 8ff98a8e8..7c03d5aed 100644
--- a/tests/app/Models/SearchTest.php
+++ b/tests/app/Models/SearchTest.php
@@ -145,14 +145,14 @@ class SearchTest extends PHPUnit\Framework\TestCase {
* @return array<array<mixed>>
*/
public static function provideDateSearch(): array {
- return array(
- array('date:2007-03-01T13:00:00Z/2008-05-11T15:30:00Z', 1172754000, 1210519800),
- array('date:2007-03-01T13:00:00Z/P1Y2M10DT2H30M', 1172754000, 1210519799),
- array('date:P1Y2M10DT2H30M/2008-05-11T15:30:00Z', 1172754001, 1210519800),
- array('date:2007-03-01/2008-05-11', strtotime('2007-03-01'), strtotime('2008-05-12') - 1),
- array('date:2007-03-01/', strtotime('2007-03-01'), null),
- array('date:/2008-05-11', null, strtotime('2008-05-12') - 1),
- );
+ return [
+ ['date:2007-03-01T13:00:00Z/2008-05-11T15:30:00Z', 1172754000, 1210519800],
+ ['date:2007-03-01T13:00:00Z/P1Y2M10DT2H30M', 1172754000, 1210519799],
+ ['date:P1Y2M10DT2H30M/2008-05-11T15:30:00Z', 1172754001, 1210519800],
+ ['date:2007-03-01/2008-05-11', strtotime('2007-03-01'), strtotime('2008-05-12') - 1],
+ ['date:2007-03-01/', strtotime('2007-03-01'), null],
+ ['date:/2008-05-11', null, strtotime('2008-05-12') - 1],
+ ];
}
#[DataProvider('providePubdateSearch')]
@@ -166,14 +166,14 @@ class SearchTest extends PHPUnit\Framework\TestCase {
* @return array<array<mixed>>
*/
public static function providePubdateSearch(): array {
- return array(
- array('pubdate:2007-03-01T13:00:00Z/2008-05-11T15:30:00Z', 1172754000, 1210519800),
- array('pubdate:2007-03-01T13:00:00Z/P1Y2M10DT2H30M', 1172754000, 1210519799),
- array('pubdate:P1Y2M10DT2H30M/2008-05-11T15:30:00Z', 1172754001, 1210519800),
- array('pubdate:2007-03-01/2008-05-11', strtotime('2007-03-01'), strtotime('2008-05-12') - 1),
- array('pubdate:2007-03-01/', strtotime('2007-03-01'), null),
- array('pubdate:/2008-05-11', null, strtotime('2008-05-12') - 1),
- );
+ return [
+ ['pubdate:2007-03-01T13:00:00Z/2008-05-11T15:30:00Z', 1172754000, 1210519800],
+ ['pubdate:2007-03-01T13:00:00Z/P1Y2M10DT2H30M', 1172754000, 1210519799],
+ ['pubdate:P1Y2M10DT2H30M/2008-05-11T15:30:00Z', 1172754001, 1210519800],
+ ['pubdate:2007-03-01/2008-05-11', strtotime('2007-03-01'), strtotime('2008-05-12') - 1],
+ ['pubdate:2007-03-01/', strtotime('2007-03-01'), null],
+ ['pubdate:/2008-05-11', null, strtotime('2008-05-12') - 1],
+ ];
}
/**
@@ -229,56 +229,56 @@ class SearchTest extends PHPUnit\Framework\TestCase {
/** @return array<array<mixed>> */
public static function provideMultipleSearch(): array {
- return array(
- array(
+ return [
+ [
'author:word1 date:2007-03-01/2008-05-11 intitle:word2 inurl:word3 pubdate:2007-03-01/2008-05-11 #word4 #word5',
- array('word1'),
+ ['word1'],
strtotime('2007-03-01'),
strtotime('2008-05-12') - 1,
- array('word2'),
- array('word3'),
+ ['word2'],
+ ['word3'],
strtotime('2007-03-01'),
strtotime('2008-05-12') - 1,
- array('word4', 'word5'),
- null,
- ),
- array(
+ ['word4', 'word5'],
+ null
+ ],
+ [
'word6 intitle:word2 inurl:word3 pubdate:2007-03-01/2008-05-11 #word4 author:word1 #word5 date:2007-03-01/2008-05-11',
- array('word1'),
+ ['word1'],
strtotime('2007-03-01'),
strtotime('2008-05-12') - 1,
- array('word2'),
- array('word3'),
+ ['word2'],
+ ['word3'],
strtotime('2007-03-01'),
strtotime('2008-05-12') - 1,
- array('word4', 'word5'),
- array('word6'),
- ),
- array(
+ ['word4', 'word5'],
+ ['word6']
+ ],
+ [
'word6 intitle:word2 inurl:word3 pubdate:2007-03-01/2008-05-11 #word4 author:word1 #word5 word7 date:2007-03-01/2008-05-11',
- array('word1'),
+ ['word1'],
strtotime('2007-03-01'),
strtotime('2008-05-12') - 1,
- array('word2'),
- array('word3'),
+ ['word2'],
+ ['word3'],
strtotime('2007-03-01'),
strtotime('2008-05-12') - 1,
- array('word4', 'word5'),
- array('word6', 'word7'),
- ),
- array(
+ ['word4', 'word5'],
+ ['word6', 'word7']
+ ],
+ [
'word6 intitle:word2 inurl:word3 pubdate:2007-03-01/2008-05-11 #word4 author:word1 #word5 "word7 word8" date:2007-03-01/2008-05-11',
- array('word1'),
+ ['word1'],
strtotime('2007-03-01'),
strtotime('2008-05-12') - 1,
- array('word2'),
- array('word3'),
+ ['word2'],
+ ['word3'],
strtotime('2007-03-01'),
strtotime('2008-05-12') - 1,
- array('word4', 'word5'),
- array('word7 word8', 'word6'),
- ),
- );
+ ['word4', 'word5'],
+ ['word7 word8', 'word6']
+ ]
+ ];
}
#[DataProvider('provideAddOrParentheses')]
@@ -349,7 +349,7 @@ class SearchTest extends PHPUnit\Framework\TestCase {
'#tag Hello OR (author:Alice inurl:example) OR (f:3 intitle:World) OR L:12',
" ((TRIM(e.tags) || ' #' LIKE ? AND (e.title LIKE ? OR e.content LIKE ?) )) OR ((e.author LIKE ? AND e.link LIKE ? )) OR" .
' ((e.id_feed IN (?) AND e.title LIKE ? )) OR ((e.id IN (SELECT et.id_entry FROM `_entrytag` et WHERE et.id_tag IN (?)) )) ',
- ['%tag #%','%Hello%', '%Hello%', '%Alice%', '%example%', '3', '%World%', '12']
+ ['%tag #%', '%Hello%', '%Hello%', '%Alice%', '%example%', '3', '%World%', '12']
],
[
'#tag Hello (author:Alice inurl:example) (f:3 intitle:World) label:Bleu',
@@ -412,13 +412,13 @@ class SearchTest extends PHPUnit\Framework\TestCase {
[
'(ab) cd OR ef OR (gh)',
'(((e.title LIKE ? OR e.content LIKE ?) )) AND (((e.title LIKE ? OR e.content LIKE ?) )) ' .
- 'OR (((e.title LIKE ? OR e.content LIKE ?) )) OR (((e.title LIKE ? OR e.content LIKE ?) ))',
+ 'OR (((e.title LIKE ? OR e.content LIKE ?) )) OR (((e.title LIKE ? OR e.content LIKE ?) ))',
['%ab%', '%ab%', '%cd%', '%cd%', '%ef%', '%ef%', '%gh%', '%gh%'],
],
[
'(ab) OR cd OR ef OR (gh)',
'(((e.title LIKE ? OR e.content LIKE ?) )) OR (((e.title LIKE ? OR e.content LIKE ?) )) ' .
- 'OR (((e.title LIKE ? OR e.content LIKE ?) )) OR (((e.title LIKE ? OR e.content LIKE ?) ))',
+ 'OR (((e.title LIKE ? OR e.content LIKE ?) )) OR (((e.title LIKE ? OR e.content LIKE ?) ))',
['%ab%', '%ab%', '%cd%', '%cd%', '%ef%', '%ef%', '%gh%', '%gh%'],
],
[
@@ -439,19 +439,19 @@ class SearchTest extends PHPUnit\Framework\TestCase {
[
'(ab (!cd OR ef OR (gh))) OR !(ij OR kl)',
'((((e.title LIKE ? OR e.content LIKE ?) )) AND (((e.title NOT LIKE ? AND e.content NOT LIKE ? )) OR (((e.title LIKE ? OR e.content LIKE ?) )) ' .
- 'OR (((e.title LIKE ? OR e.content LIKE ?) )))) OR NOT (((e.title LIKE ? OR e.content LIKE ?) ) OR ((e.title LIKE ? OR e.content LIKE ?) ))',
+ 'OR (((e.title LIKE ? OR e.content LIKE ?) )))) OR NOT (((e.title LIKE ? OR e.content LIKE ?) ) OR ((e.title LIKE ? OR e.content LIKE ?) ))',
['%ab%', '%ab%', '%cd%', '%cd%', '%ef%', '%ef%', '%gh%', '%gh%', '%ij%', '%ij%', '%kl%', '%kl%'],
],
[
'"ab" "cd" ("ef") intitle:"gh" !"ij" -"kl"',
'(((e.title LIKE ? OR e.content LIKE ?) AND (e.title LIKE ? OR e.content LIKE ?) )) AND (((e.title LIKE ? OR e.content LIKE ?) )) ' .
- 'AND ((e.title LIKE ? AND e.title NOT LIKE ? AND e.content NOT LIKE ? AND e.title NOT LIKE ? AND e.content NOT LIKE ? ))',
+ 'AND ((e.title LIKE ? AND e.title NOT LIKE ? AND e.content NOT LIKE ? AND e.title NOT LIKE ? AND e.content NOT LIKE ? ))',
['%ab%', '%ab%', '%cd%', '%cd%', '%ef%', '%ef%', '%gh%', '%ij%', '%ij%', '%kl%', '%kl%']
],
[
'&quot;ab&quot; &quot;cd&quot; (&quot;ef&quot;) intitle:&quot;gh&quot; !&quot;ij&quot; -&quot;kl&quot;',
'(((e.title LIKE ? OR e.content LIKE ?) AND (e.title LIKE ? OR e.content LIKE ?) )) AND (((e.title LIKE ? OR e.content LIKE ?) )) ' .
- 'AND ((e.title LIKE ? AND e.title NOT LIKE ? AND e.content NOT LIKE ? AND e.title NOT LIKE ? AND e.content NOT LIKE ? ))',
+ 'AND ((e.title LIKE ? AND e.title NOT LIKE ? AND e.content NOT LIKE ? AND e.title NOT LIKE ? AND e.content NOT LIKE ? ))',
['%ab%', '%ab%', '%cd%', '%cd%', '%ef%', '%ef%', '%gh%', '%ij%', '%ij%', '%kl%', '%kl%']
],
[
diff --git a/tests/app/Models/UserQueryTest.php b/tests/app/Models/UserQueryTest.php
index f9577e49b..70483aed1 100644
--- a/tests/app/Models/UserQueryTest.php
+++ b/tests/app/Models/UserQueryTest.php
@@ -1,19 +1,20 @@
<?php
declare(strict_types=1);
+use PHPUnit\Framework\TestCase;
/**
* Description of UserQueryTest
*/
-class UserQueryTest extends PHPUnit\Framework\TestCase {
+class UserQueryTest extends TestCase {
public static function test__construct_whenAllQuery_storesAllParameters(): void {
- $query = array('get' => 'a');
+ $query = ['get' => 'a'];
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertEquals('all', $user_query->getGetType());
}
public static function test__construct_whenFavoriteQuery_storesFavoriteParameters(): void {
- $query = array('get' => 's');
+ $query = ['get' => 's'];
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertEquals('favorite', $user_query->getGetType());
}
@@ -26,7 +27,7 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {
->method('name')
->withAnyParameters()
->willReturn($category_name);
- $query = array('get' => 'c_1');
+ $query = ['get' => 'c_1'];
$user_query = new FreshRSS_UserQuery($query, [1 => $cat], []);
self::assertEquals($category_name, $user_query->getGetName());
self::assertEquals('category', $user_query->getGetType());
@@ -50,14 +51,14 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {
->method('feeds')
->withAnyParameters()
->willReturn([1 => $feed]);
- $query = array('get' => 'f_1');
+ $query = ['get' => 'f_1'];
$user_query = new FreshRSS_UserQuery($query, [1 => $cat], []);
self::assertEquals($feed_name, $user_query->getGetName());
self::assertEquals('feed', $user_query->getGetType());
}
public static function test__construct_whenUnknownQuery_doesStoreParameters(): void {
- $query = array('get' => 'q');
+ $query = ['get' => 'q'];
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertEmpty($user_query->getGetName());
self::assertEmpty($user_query->getGetType());
@@ -65,28 +66,28 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {
public static function test__construct_whenName_storesName(): void {
$name = 'some name';
- $query = array('name' => $name);
+ $query = ['name' => $name];
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertEquals($name, $user_query->getName());
}
public static function test__construct_whenOrder_storesOrder(): void {
$order = 'some order';
- $query = array('order' => $order);
+ $query = ['order' => $order];
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertEquals($order, $user_query->getOrder());
}
public static function test__construct_whenState_storesState(): void {
$state = FreshRSS_Entry::STATE_NOT_READ | FreshRSS_Entry::STATE_FAVORITE;
- $query = array('state' => $state);
+ $query = ['state' => $state];
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertEquals($state, $user_query->getState());
}
public static function test__construct_whenUrl_storesUrl(): void {
$url = 'some url';
- $query = array('url' => $url);
+ $query = ['url' => $url];
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertEquals($url, $user_query->getUrl());
}
@@ -97,23 +98,21 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {
}
public static function testToArray_whenData_returnsArray(): void {
- $query = array(
+ $query = [
'get' => 's',
'name' => 'some name',
'order' => 'some order',
'search' => 'some search',
'state' => FreshRSS_Entry::STATE_ALL,
'url' => 'some url',
- );
+ ];
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertCount(6, $user_query->toArray());
self::assertEquals($query, $user_query->toArray());
}
public static function testHasSearch_whenSearch_returnsTrue(): void {
- $query = array(
- 'search' => 'some search',
- );
+ $query = ['search' => 'some search'];
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertTrue($user_query->hasSearch());
}
@@ -124,19 +123,19 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {
}
public static function testHasParameters_whenAllQuery_returnsFalse(): void {
- $query = array('get' => 'a');
+ $query = ['get' => 'a'];
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertFalse($user_query->hasParameters());
}
public static function testHasParameters_whenNoParameter_returnsFalse(): void {
- $query = array();
+ $query = [];
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertFalse($user_query->hasParameters());
}
public static function testHasParameters_whenParameter_returnTrue(): void {
- $query = array('get' => 's');
+ $query = ['get' => 's'];
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertTrue($user_query->hasParameters());
}
@@ -148,13 +147,13 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {
->method('name')
->withAnyParameters()
->willReturn('cat 1');
- $query = array('get' => 'c_1');
+ $query = ['get' => 'c_1'];
$user_query = new FreshRSS_UserQuery($query, [1 => $cat], []);
self::assertFalse($user_query->isDeprecated());
}
public static function testIsDeprecated_whenCategoryDoesNotExist_returnTrue(): void {
- $query = array('get' => 'c_1');
+ $query = ['get' => 'c_1'];
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertTrue($user_query->isDeprecated());
}
@@ -176,7 +175,7 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {
->method('feeds')
->withAnyParameters()
->willReturn([1 => $feed]);
- $query = array('get' => 'f_1');
+ $query = ['get' => 'f_1'];
$user_query = new FreshRSS_UserQuery($query, [1 => $cat], []);
self::assertFalse($user_query->isDeprecated());
}
@@ -188,25 +187,25 @@ class UserQueryTest extends PHPUnit\Framework\TestCase {
->method('feeds')
->withAnyParameters()
->willReturn([]);
- $query = array('get' => 'f_1');
+ $query = ['get' => 'f_1'];
$user_query = new FreshRSS_UserQuery($query, [1 => $cat], []);
self::assertTrue($user_query->isDeprecated());
}
public static function testIsDeprecated_whenAllQuery_returnFalse(): void {
- $query = array('get' => 'a');
+ $query = ['get' => 'a'];
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertFalse($user_query->isDeprecated());
}
public static function testIsDeprecated_whenFavoriteQuery_returnFalse(): void {
- $query = array('get' => 's');
+ $query = ['get' => 's'];
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertFalse($user_query->isDeprecated());
}
public static function testIsDeprecated_whenUnknownQuery_returnFalse(): void {
- $query = array('get' => 'q');
+ $query = ['get' => 'q'];
$user_query = new FreshRSS_UserQuery($query, [], []);
self::assertFalse($user_query->isDeprecated());
}