summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--classes/API.php24
-rw-r--r--classes/Config.php13
-rw-r--r--classes/FeedParser.php22
-rw-r--r--classes/Feeds.php54
-rw-r--r--classes/Logger.php19
-rw-r--r--classes/OPML.php19
-rw-r--r--classes/Pref_System.php15
-rw-r--r--classes/RPC.php15
-rw-r--r--classes/UserHelper.php36
9 files changed, 75 insertions, 142 deletions
diff --git a/classes/API.php b/classes/API.php
index 290c813ed..e808376ed 100644
--- a/classes/API.php
+++ b/classes/API.php
@@ -241,7 +241,6 @@ class API extends Handler {
$field_raw = (int)clean($_REQUEST["field"]);
$field = "";
- $set_to = "";
$additional_fields = "";
switch ($field_raw) {
@@ -265,20 +264,17 @@ class API extends Handler {
break;
};
- switch ($mode) {
- case 1:
- $set_to = "true";
- break;
- case 0:
- $set_to = "false";
- break;
- case 2:
- $set_to = "NOT $field";
- break;
- }
+ $set_to = match ($mode) {
+ 0 => 'false',
+ 1 => 'true',
+ 2 => "NOT $field",
+ default => null,
+ };
- if ($field == "note") $set_to = $this->pdo->quote($data);
- if ($field == "score") $set_to = (int) $data;
+ if ($field == 'note')
+ $set_to = $this->pdo->quote($data);
+ elseif ($field == 'score')
+ $set_to = (int) $data;
if ($field && $set_to && count($article_ids) > 0) {
diff --git a/classes/Config.php b/classes/Config.php
index e269fde30..4775faf71 100644
--- a/classes/Config.php
+++ b/classes/Config.php
@@ -424,14 +424,11 @@ class Config {
}
static function cast_to(string $value, int $type_hint): bool|int|string {
- switch ($type_hint) {
- case self::T_BOOL:
- return sql_bool_to_bool($value);
- case self::T_INT:
- return (int) $value;
- default:
- return $value;
- }
+ return match ($type_hint) {
+ self::T_BOOL => sql_bool_to_bool($value),
+ self::T_INT => (int) $value,
+ default => $value,
+ };
}
private function _get(string $param): bool|int|string {
diff --git a/classes/FeedParser.php b/classes/FeedParser.php
index 729d77206..105708aa2 100644
--- a/classes/FeedParser.php
+++ b/classes/FeedParser.php
@@ -72,19 +72,15 @@ class FeedParser {
$root = $root_list->item(0);
if ($root) {
- switch (mb_strtolower($root->tagName)) {
- case "rdf:rdf":
- $this->type = $this::FEED_RDF;
- break;
- case "channel":
- $this->type = $this::FEED_RSS;
- break;
- case "feed":
- case "atom:feed":
- $this->type = $this::FEED_ATOM;
- break;
- default:
- $this->error ??= "Unknown/unsupported feed type";
+ $this->type = match (mb_strtolower($root->tagName)) {
+ 'rdf:rdf' => $this::FEED_RDF,
+ 'channel' => $this::FEED_RSS,
+ 'feed', 'atom:feed' => $this::FEED_ATOM,
+ default => null,
+ };
+
+ if (!$this->type) {
+ $this->error ??= 'Unknown/unsupported feed type';
return;
}
}
diff --git a/classes/Feeds.php b/classes/Feeds.php
index 504b96db3..d3a28fe8d 100644
--- a/classes/Feeds.php
+++ b/classes/Feeds.php
@@ -397,23 +397,14 @@ class Feeds extends Handler_Protected {
if ($query_error_override) {
$message = $query_error_override;
} else {
- switch ($view_mode) {
- case "unread":
- $message = __("No unread articles found to display.");
- break;
- case "updated":
- $message = __("No updated articles found to display.");
- break;
- case "marked":
- $message = __("No starred articles found to display.");
- break;
- default:
- if ($feed < LABEL_BASE_INDEX) {
- $message = __("No articles found to display. You can assign articles to labels manually from article header context menu (applies to all selected articles) or use a filter.");
- } else {
- $message = __("No articles found to display.");
- }
- }
+ $message = match ($view_mode) {
+ 'unread' => __('No unread articles found to display.'),
+ 'updated' => __('No updated articles found to display.'),
+ 'marked' => __('No starred articles found to display.'),
+ default => $feed < LABEL_BASE_INDEX ?
+ __('No articles found to display. You can assign articles to labels manually from article header context menu (applies to all selected articles) or use a filter.')
+ : __('No articles found to display.'),
+ };
}
if (!$offset && $message) {
@@ -1153,26 +1144,15 @@ class Feeds extends Handler_Protected {
* @return false|string false if the icon ID was unrecognized, otherwise, the icon identifier string
*/
static function _get_icon(int $id): false|string {
- switch ($id) {
- case Feeds::FEED_ARCHIVED:
- return "archive";
- case Feeds::FEED_STARRED:
- return "star";
- case Feeds::FEED_PUBLISHED:
- return "rss_feed";
- case Feeds::FEED_FRESH:
- return "whatshot";
- case Feeds::FEED_ALL:
- return "inbox";
- case Feeds::FEED_RECENTLY_READ:
- return "restore";
- default:
- if ($id < LABEL_BASE_INDEX) {
- return "label";
- } else {
- return self::_get_icon_url($id);
- }
- }
+ return match ($id) {
+ Feeds::FEED_ARCHIVED => 'archive',
+ Feeds::FEED_STARRED => 'star',
+ Feeds::FEED_PUBLISHED => 'rss_feed',
+ Feeds::FEED_FRESH => 'whatshot',
+ Feeds::FEED_ALL => 'inbox',
+ Feeds::FEED_RECENTLY_READ => 'restore',
+ default => $id < LABEL_BASE_INDEX ? 'label' : self::_get_icon_url($id),
+ };
}
/**
diff --git a/classes/Logger.php b/classes/Logger.php
index ef6173a42..049b63d5e 100644
--- a/classes/Logger.php
+++ b/classes/Logger.php
@@ -57,19 +57,12 @@ class Logger {
}
function __construct() {
- switch (Config::get(Config::LOG_DESTINATION)) {
- case self::LOG_DEST_SQL:
- $this->adapter = new Logger_SQL();
- break;
- case self::LOG_DEST_SYSLOG:
- $this->adapter = new Logger_Syslog();
- break;
- case self::LOG_DEST_STDOUT:
- $this->adapter = new Logger_Stdout();
- break;
- default:
- $this->adapter = null;
- }
+ $this->adapter = match (Config::get(Config::LOG_DESTINATION)) {
+ self::LOG_DEST_SQL => new Logger_SQL(),
+ self::LOG_DEST_SYSLOG => new Logger_Syslog(),
+ self::LOG_DEST_STDOUT => new Logger_Stdout(),
+ default => null,
+ };
if ($this->adapter && !implements_interface($this->adapter, "Logger_Adapter"))
user_error("Adapter for LOG_DESTINATION: " . Config::LOG_DESTINATION . " does not implement required interface.", E_USER_ERROR);
diff --git a/classes/OPML.php b/classes/OPML.php
index fcc858de6..e2ec6a7ff 100644
--- a/classes/OPML.php
+++ b/classes/OPML.php
@@ -590,19 +590,12 @@ class OPML extends Handler_Protected {
$dst_cat_id = $cat_id;
}
- switch ($cat_title) {
- case "tt-rss-prefs":
- $this->opml_import_preference($node, $owner_uid, $nest+1);
- break;
- case "tt-rss-labels":
- $this->opml_import_label($node, $owner_uid, $nest+1);
- break;
- case "tt-rss-filters":
- $this->opml_import_filter($node, $owner_uid, $nest+1);
- break;
- default:
- $this->opml_import_feed($node, $dst_cat_id, $owner_uid, $nest+1);
- }
+ match ($cat_title) {
+ 'tt-rss-prefs' => $this->opml_import_preference($node, $owner_uid, $nest+1),
+ 'tt-rss-labels' => $this->opml_import_label($node, $owner_uid, $nest+1),
+ 'tt-rss-filters' => $this->opml_import_filter($node, $owner_uid, $nest+1),
+ default => $this->opml_import_feed($node, $dst_cat_id, $owner_uid, $nest+1),
+ };
}
}
}
diff --git a/classes/Pref_System.php b/classes/Pref_System.php
index 2220199e7..885eabdac 100644
--- a/classes/Pref_System.php
+++ b/classes/Pref_System.php
@@ -38,16 +38,11 @@ class Pref_System extends Handler_Administrative {
}
private function _log_viewer(int $page, int $severity): void {
- $errno_values = [];
-
- switch ($severity) {
- case E_USER_ERROR:
- $errno_values = [ E_ERROR, E_USER_ERROR, E_PARSE, E_COMPILE_ERROR ];
- break;
- case E_USER_WARNING:
- $errno_values = [ E_ERROR, E_USER_ERROR, E_PARSE, E_COMPILE_ERROR, E_WARNING, E_USER_WARNING, E_DEPRECATED, E_USER_DEPRECATED ];
- break;
- }
+ $errno_values = match ($severity) {
+ E_USER_ERROR => [E_ERROR, E_USER_ERROR, E_PARSE, E_COMPILE_ERROR],
+ E_USER_WARNING => [E_ERROR, E_USER_ERROR, E_PARSE, E_COMPILE_ERROR, E_WARNING, E_USER_WARNING, E_DEPRECATED, E_USER_DEPRECATED],
+ default => [],
+ };
if (count($errno_values) > 0) {
$errno_qmarks = arr_qmarks($errno_values);
diff --git a/classes/RPC.php b/classes/RPC.php
index 4f7df652c..6edc88480 100644
--- a/classes/RPC.php
+++ b/classes/RPC.php
@@ -785,16 +785,11 @@ class RPC extends Handler_Protected {
if (strlen($keys[$i]) > 1) {
$tmp = '';
foreach (str_split($keys[$i]) as $c) {
- switch ($c) {
- case '*':
- $tmp .= __('Shift') . '+';
- break;
- case '^':
- $tmp .= __('Ctrl') . '+';
- break;
- default:
- $tmp .= $c;
- }
+ $tmp .= match ($c) {
+ '*' => __('Shift') . '+',
+ '^' => __('Ctrl') . '+',
+ default => $c,
+ };
}
$keys[$i] = $tmp;
}
diff --git a/classes/UserHelper.php b/classes/UserHelper.php
index 21c2ab4d5..de0b5a6ed 100644
--- a/classes/UserHelper.php
+++ b/classes/UserHelper.php
@@ -383,30 +383,18 @@ class UserHelper {
* @return false|string False if the password couldn't be hashed, otherwise the hash string.
*/
static function hash_password(string $pass, string $salt, string $algo = self::HASH_ALGOS[0]): false|string {
- $pass_hash = "";
-
- switch ($algo) {
- case self::HASH_ALGO_SHA1:
- $pass_hash = sha1($pass);
- break;
- case self::HASH_ALGO_SHA1X:
- $pass_hash = sha1("$salt:$pass");
- break;
- case self::HASH_ALGO_MODE2:
- case self::HASH_ALGO_SSHA256:
- $pass_hash = hash('sha256', $salt . $pass);
- break;
- case self::HASH_ALGO_SSHA512:
- $pass_hash = hash('sha512', $salt . $pass);
- break;
- default:
- user_error("hash_password: unknown hash algo: $algo", E_USER_ERROR);
- }
-
- if ($pass_hash)
- return "$algo:$pass_hash";
- else
- return false;
+ $pass_hash = match ($algo) {
+ self::HASH_ALGO_SHA1 => sha1($pass),
+ self::HASH_ALGO_SHA1X => sha1("$salt:$pass"),
+ self::HASH_ALGO_MODE2, self::HASH_ALGO_SSHA256 => hash('sha256', $salt . $pass),
+ self::HASH_ALGO_SSHA512 => hash('sha512', $salt . $pass),
+ default => null,
+ };
+
+ if ($pass_hash === null)
+ user_error("hash_password: unknown hash algo: $algo", E_USER_ERROR);
+
+ return $pass_hash ? "$algo:$pass_hash" : false;
}
/**