Use the null coalescing assignment operator in various places.

This commit is contained in:
wn_ 2022-08-12 18:21:38 +00:00
parent 3487c922b3
commit c301053965
6 changed files with 22 additions and 42 deletions

View File

@ -43,10 +43,8 @@ class FeedParser {
foreach (libxml_get_errors() as $error) { foreach (libxml_get_errors() as $error) {
if ($error->level == LIBXML_ERR_FATAL) { if ($error->level == LIBXML_ERR_FATAL) {
// currently only the first error is reported // currently only the first error is reported
if (!isset($this->error)) { $this->error ??= Errors::format_libxml_error($error);
$this->error = $this->format_error($error); $this->libxml_errors[] = Errors::format_libxml_error($error);
}
$this->libxml_errors[] = $this->format_error($error);
} }
} }
} }
@ -87,9 +85,7 @@ class FeedParser {
$this->type = $this::FEED_ATOM; $this->type = $this::FEED_ATOM;
break; break;
default: default:
if (!isset($this->error)) { $this->error ??= "Unknown/unsupported feed type";
$this->error = "Unknown/unsupported feed type";
}
return; return;
} }
} }
@ -186,9 +182,7 @@ class FeedParser {
if ($this->link) $this->link = trim($this->link); if ($this->link) $this->link = trim($this->link);
} else { } else {
if (!isset($this->error)) { $this->error ??= "Unknown/unsupported feed type";
$this->error = "Unknown/unsupported feed type";
}
return; return;
} }
} }

View File

@ -412,8 +412,7 @@ class Handler_Public extends Handler {
if (session_status() != PHP_SESSION_ACTIVE) if (session_status() != PHP_SESSION_ACTIVE)
session_start(); session_start();
if (!isset($_SESSION["login_error_msg"])) $_SESSION["login_error_msg"] ??= __("Incorrect username or password");
$_SESSION["login_error_msg"] = __("Incorrect username or password");
} }
$return = clean($_REQUEST['return']); $return = clean($_REQUEST['return']);

View File

@ -535,10 +535,7 @@ class PluginHost {
$method = strtolower($method); $method = strtolower($method);
if ($this->is_system($sender)) { if ($this->is_system($sender)) {
if (!isset($this->handlers[$handler])) { $this->handlers[$handler] ??= [];
$this->handlers[$handler] = [];
}
$this->handlers[$handler][$method] = $sender; $this->handlers[$handler][$method] = $sender;
} }
} }
@ -641,8 +638,7 @@ class PluginHost {
owner_uid= ? AND name = ?"); owner_uid= ? AND name = ?");
$sth->execute([$this->owner_uid, $plugin]); $sth->execute([$this->owner_uid, $plugin]);
if (!isset($this->storage[$plugin])) $this->storage[$plugin] ??= [];
$this->storage[$plugin] = [];
$content = serialize($this->storage[$plugin]); $content = serialize($this->storage[$plugin]);
@ -673,14 +669,8 @@ class PluginHost {
if ($profile_id) { if ($profile_id) {
$idx = get_class($sender); $idx = get_class($sender);
if (!isset($this->storage[$idx])) { $this->storage[$idx] ??= [];
$this->storage[$idx] = []; $this->storage[$idx][$profile_id] ??= [];
}
if (!isset($this->storage[$idx][$profile_id])) {
$this->storage[$idx][$profile_id] = [];
}
$this->storage[$idx][$profile_id][$name] = $value; $this->storage[$idx][$profile_id][$name] = $value;
$this->save_data(get_class($sender)); $this->save_data(get_class($sender));
@ -695,9 +685,7 @@ class PluginHost {
function set(Plugin $sender, string $name, $value): void { function set(Plugin $sender, string $name, $value): void {
$idx = get_class($sender); $idx = get_class($sender);
if (!isset($this->storage[$idx])) $this->storage[$idx] ??= [];
$this->storage[$idx] = [];
$this->storage[$idx][$name] = $value; $this->storage[$idx][$name] = $value;
$this->save_data(get_class($sender)); $this->save_data(get_class($sender));
@ -709,8 +697,7 @@ class PluginHost {
function set_array(Plugin $sender, array $params): void { function set_array(Plugin $sender, array $params): void {
$idx = get_class($sender); $idx = get_class($sender);
if (!isset($this->storage[$idx])) $this->storage[$idx] ??= [];
$this->storage[$idx] = [];
foreach ($params as $name => $value) foreach ($params as $name => $value)
$this->storage[$idx][$name] = $value; $this->storage[$idx][$name] = $value;
@ -848,11 +835,13 @@ class PluginHost {
function add_filter_action(Plugin $sender, string $action_name, string $action_desc): void { function add_filter_action(Plugin $sender, string $action_name, string $action_desc): void {
$sender_class = get_class($sender); $sender_class = get_class($sender);
if (!isset($this->plugin_actions[$sender_class])) $this->plugin_actions[$sender_class] ??= [];
$this->plugin_actions[$sender_class] = [];
array_push($this->plugin_actions[$sender_class], $this->plugin_actions[$sender_class][] = [
array("action" => $action_name, "description" => $action_desc, "sender" => $sender)); "action" => $action_name,
"description" => $action_desc,
"sender" => $sender,
];
} }
/** /**

View File

@ -185,7 +185,7 @@ class Pref_Prefs extends Handler_Protected {
$boolean_prefs = explode(",", clean($_POST["boolean_prefs"])); $boolean_prefs = explode(",", clean($_POST["boolean_prefs"]));
foreach ($boolean_prefs as $pref) { foreach ($boolean_prefs as $pref) {
if (!isset($_POST[$pref])) $_POST[$pref] = 'false'; $_POST[$pref] ??= 'false';
} }
$need_reload = false; $need_reload = false;

View File

@ -753,12 +753,11 @@ class RPC extends Handler_Protected {
function hotkeyHelp(): void { function hotkeyHelp(): void {
$info = self::get_hotkeys_info(); $info = self::get_hotkeys_info();
$imap = self::get_hotkeys_map(); $imap = self::get_hotkeys_map();
$omap = array(); $omap = [];
foreach ($imap[1] as $sequence => $action) { foreach ($imap[1] as $sequence => $action) {
if (!isset($omap[$action])) $omap[$action] = array(); $omap[$action] ??= [];
$omap[$action][] = $sequence;
array_push($omap[$action], $sequence);
} }
?> ?>

View File

@ -108,8 +108,7 @@
$valid_langs[$lang] = $t; $valid_langs[$lang] = $t;
$lang = substr($lang, 0, 2); $lang = substr($lang, 0, 2);
if (!isset($valid_langs[$lang])) $valid_langs[$lang] ??= $t;
$valid_langs[$lang] = $t;
} }
// break up string into pieces (languages and q factors) // break up string into pieces (languages and q factors)