Replace basic 'isset()' cases with the null coalescing operator.

This commit is contained in:
wn_ 2024-08-04 15:42:11 +00:00
parent 6b521b5ed1
commit 9dd4102c7f
9 changed files with 40 additions and 70 deletions

View File

@ -817,7 +817,7 @@ class API extends Handler {
$headline_row["labels"] = $labels;
$headline_row["feed_title"] = isset($line["feed_title"]) ? $line["feed_title"] : $feed_title;
$headline_row["feed_title"] = $line["feed_title"] ?? $feed_title;
$headline_row["comments_count"] = (int)$line["num_comments"];
$headline_row["comments_link"] = $line["comments"];

View File

@ -410,7 +410,7 @@ class DiskCache implements Cache_Adapter {
$mimetype = $this->adapter->get_mime_type(basename($filename));
if ($mimetype)
return isset($this->mimeMap[$mimetype]) ? $this->mimeMap[$mimetype] : "";
return $this->mimeMap[$mimetype] ?? "";
else
return "";
}

View File

@ -1495,23 +1495,23 @@ class Feeds extends Handler_Protected {
// right before adding them to SQL part
$feed = $params["feed"];
$limit = isset($params["limit"]) ? $params["limit"] : 30;
$limit = $params["limit"] ?? 30;
$view_mode = $params["view_mode"];
$cat_view = isset($params["cat_view"]) ? $params["cat_view"] : false;
$search = isset($params["search"]) ? $params["search"] : false;
$search_language = isset($params["search_language"]) ? $params["search_language"] : "";
$override_order = isset($params["override_order"]) ? $params["override_order"] : false;
$offset = isset($params["offset"]) ? $params["offset"] : 0;
$owner_uid = isset($params["owner_uid"]) ? $params["owner_uid"] : $_SESSION["uid"];
$since_id = isset($params["since_id"]) ? $params["since_id"] : 0;
$include_children = isset($params["include_children"]) ? $params["include_children"] : false;
$ignore_vfeed_group = isset($params["ignore_vfeed_group"]) ? $params["ignore_vfeed_group"] : false;
$override_strategy = isset($params["override_strategy"]) ? $params["override_strategy"] : false;
$override_vfeed = isset($params["override_vfeed"]) ? $params["override_vfeed"] : false;
$start_ts = isset($params["start_ts"]) ? $params["start_ts"] : false;
$check_first_id = isset($params["check_first_id"]) ? $params["check_first_id"] : false;
$skip_first_id_check = isset($params["skip_first_id_check"]) ? $params["skip_first_id_check"] : false;
//$order_by = isset($params["order_by"]) ? $params["order_by"] : false;
$cat_view = $params["cat_view"] ?? false;
$search = $params["search"] ?? false;
$search_language = $params["search_language"] ?? "";
$override_order = $params["override_order"] ?? false;
$offset = $params["offset"] ?? 0;
$owner_uid = $params["owner_uid"] ?? $_SESSION["uid"];
$since_id = $params["since_id"] ?? 0;
$include_children = $params["include_children"] ?? false;
$ignore_vfeed_group = $params["ignore_vfeed_group"] ?? false;
$override_strategy = $params["override_strategy"] ?? false;
$override_vfeed = $params["override_vfeed"] ?? false;
$start_ts = $params["start_ts"] ?? false;
$check_first_id = $params["check_first_id"] ?? false;
$skip_first_id_check = $params["skip_first_id_check"] ?? false;
//$order_by = $params["order_by"] ?? false;
$ext_tables_part = "";
$limit_query_part = "";

View File

@ -586,11 +586,7 @@ class PluginHost {
$method = strtolower($method);
if (isset($this->handlers[$handler])) {
if (isset($this->handlers[$handler]["*"])) {
return $this->handlers[$handler]["*"];
} else {
return $this->handlers[$handler][$method];
}
return $this->handlers[$handler]["*"] ?? $this->handlers[$handler][$method];
}
return false;
@ -752,15 +748,8 @@ class PluginHost {
if ($profile_id) {
$idx = get_class($sender);
$this->load_data();
if (isset($this->storage[$idx][$profile_id][$name])) {
return $this->storage[$idx][$profile_id][$name];
} else {
return $default_value;
}
return $this->storage[$idx][$profile_id][$name] ?? $default_value;
} else {
return $this->get($sender, $name, $default_value);
}
@ -772,14 +761,8 @@ class PluginHost {
*/
function get(Plugin $sender, string $name, $default_value = false) {
$idx = get_class($sender);
$this->load_data();
if (isset($this->storage[$idx][$name])) {
return $this->storage[$idx][$name];
} else {
return $default_value;
}
return $this->storage[$idx][$name] ?? $default_value;
}
/**

View File

@ -1481,17 +1481,11 @@ class Pref_Prefs extends Handler_Protected {
}
private function _get_short_desc(string $pref_name): string {
if (isset($this->pref_help[$pref_name][0])) {
return $this->pref_help[$pref_name][0];
}
return "";
return $this->pref_help[$pref_name][0] ?? "";
}
private function _get_help_text(string $pref_name): string {
if (isset($this->pref_help[$pref_name][1])) {
return $this->pref_help[$pref_name][1];
}
return "";
return $this->pref_help[$pref_name][1] ?? "";
}
private function appPasswordList(): void {

View File

@ -303,11 +303,7 @@ class Prefs {
*/
private function _get_cache(string $pref_name, int $owner_uid, ?int $profile_id) {
$cache_key = sprintf("%d/%d/%s", $owner_uid, $profile_id, $pref_name);
if (isset($this->cache[$cache_key]))
return $this->cache[$cache_key];
return null;
return $this->cache[$cache_key] ?? null;
}
/**

View File

@ -276,19 +276,19 @@ class UrlHelper {
}
$url = $options["url"];
$type = isset($options["type"]) ? $options["type"] : false;
$login = isset($options["login"]) ? $options["login"] : false;
$pass = isset($options["pass"]) ? $options["pass"] : false;
$auth_type = isset($options["auth_type"]) ? $options["auth_type"] : "basic";
$post_query = isset($options["post_query"]) ? $options["post_query"] : false;
$timeout = isset($options["timeout"]) ? $options["timeout"] : false;
$last_modified = isset($options["last_modified"]) ? $options["last_modified"] : "";
$useragent = isset($options["useragent"]) ? $options["useragent"] : false;
$followlocation = isset($options["followlocation"]) ? $options["followlocation"] : true;
$max_size = isset($options["max_size"]) ? $options["max_size"] : Config::get(Config::MAX_DOWNLOAD_FILE_SIZE); // in bytes
$http_accept = isset($options["http_accept"]) ? $options["http_accept"] : false;
$http_referrer = isset($options["http_referrer"]) ? $options["http_referrer"] : false;
$encoding = isset($options["encoding"]) ? $options["encoding"] : false;
$type = $options["type"] ?? false;
$login = $options["login"] ?? false;
$pass = $options["pass"] ?? false;
$auth_type = $options["auth_type"] ?? "basic";
$post_query = $options["post_query"] ?? false;
$timeout = $options["timeout"] ?? false;
$last_modified = $options["last_modified"] ?? "";
$useragent = $options["useragent"] ?? false;
$followlocation = $options["followlocation"] ?? true;
$max_size = $options["max_size"] ?? Config::get(Config::MAX_DOWNLOAD_FILE_SIZE); // in bytes
$http_accept = $options["http_accept"] ?? false;
$http_referrer = $options["http_referrer"] ?? false;
$encoding = $options["encoding"] ?? false;
$url = ltrim($url, ' ');
$url = str_replace(' ', '%20', $url);

View File

@ -156,10 +156,7 @@ function _resolve_htmlcolor(string $color): string {
$color = strtolower($color);
if (isset($htmlcolors[$color]))
return $htmlcolors[$color];
else
return $color;
return $htmlcolors[$color] ?? $color;
}
/**

View File

@ -64,13 +64,13 @@ class Auth_Remote extends Auth_Base {
// LemonLDAP can send user informations via HTTP HEADER
if (Config::get(Config::AUTH_AUTO_CREATE)) {
// update user name
$fullname = isset($_SERVER['HTTP_USER_NAME']) ? $_SERVER['HTTP_USER_NAME'] : ($_SERVER['AUTHENTICATE_CN'] ?? "");
$fullname = $_SERVER['HTTP_USER_NAME'] ?? $_SERVER['AUTHENTICATE_CN'] ?? '';
if ($fullname){
$sth = $this->pdo->prepare("UPDATE ttrss_users SET full_name = ? WHERE id = ?");
$sth->execute([$fullname, $user_id]);
}
// update user mail
$email = isset($_SERVER['HTTP_USER_MAIL']) ? $_SERVER['HTTP_USER_MAIL'] : ($_SERVER['AUTHENTICATE_MAIL'] ?? "");
$email = $_SERVER['HTTP_USER_MAIL'] ?? $_SERVER['AUTHENTICATE_MAIL'] ?? '';
if ($email){
$sth = $this->pdo->prepare("UPDATE ttrss_users SET email = ? WHERE id = ?");
$sth->execute([$email, $user_id]);