Use arrow functions in some places.

This commit is contained in:
wn_ 2022-08-12 14:41:21 +00:00
parent 6e01d5d930
commit a63c949a55
4 changed files with 12 additions and 19 deletions

View File

@ -190,13 +190,10 @@ class Db_Migrations {
if (file_exists($filename)) { if (file_exists($filename)) {
$lines = array_filter(preg_split("/[\r\n]/", file_get_contents($filename)), $lines = array_filter(preg_split("/[\r\n]/", file_get_contents($filename)),
function ($line) { fn($line) => strlen(trim($line)) > 0 && strpos($line, "--") !== 0);
return strlen(trim($line)) > 0 && strpos($line, "--") !== 0;
});
return array_filter(explode(";", implode("", $lines)), function ($line) { return array_filter(explode(";", implode("", $lines)),
return strlen(trim($line)) > 0 && !in_array(strtolower($line), ["begin", "commit"]); fn($line) => strlen(trim($line)) > 0 && !in_array(strtolower($line), ["begin", "commit"]));
});
} else { } else {
user_error("Requested schema file ${filename} not found.", E_USER_ERROR); user_error("Requested schema file ${filename} not found.", E_USER_ERROR);

View File

@ -163,9 +163,7 @@ class Digest
$article_labels_formatted = ""; $article_labels_formatted = "";
if (is_array($article_labels) && count($article_labels) > 0) { if (is_array($article_labels) && count($article_labels) > 0) {
$article_labels_formatted = implode(", ", array_map(function($a) { $article_labels_formatted = implode(", ", array_map(fn($a) => $a[1], $article_labels));
return $a[1];
}, $article_labels));
} }
$tpl->setVariable('FEED_TITLE', $line["feed_title"]); $tpl->setVariable('FEED_TITLE', $line["feed_title"]);

View File

@ -872,13 +872,13 @@ class Pref_Prefs extends Handler_Protected {
PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_PARSED), PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_PARSED),
PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FETCH_FEED)); PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FETCH_FEED));
$feed_handlers = array_filter($feed_handlers, function($plugin) use ($feed_handler_whitelist) { $feed_handlers = array_filter($feed_handlers,
return in_array(get_class($plugin), $feed_handler_whitelist) === false; }); fn($plugin) => in_array(get_class($plugin), $feed_handler_whitelist) === false);
if (count($feed_handlers) > 0) { if (count($feed_handlers) > 0) {
print_error( print_error(
T_sprintf("The following plugins use per-feed content hooks. This may cause excessive data usage and origin server load resulting in a ban of your instance: <b>%s</b>" , T_sprintf("The following plugins use per-feed content hooks. This may cause excessive data usage and origin server load resulting in a ban of your instance: <b>%s</b>" ,
implode(", ", array_map(function($plugin) { return get_class($plugin); }, $feed_handlers)) implode(", ", array_map(fn($plugin) => get_class($plugin), $feed_handlers))
) . " (<a href='https://tt-rss.org/wiki/FeedHandlerPlugins' target='_blank'>".__("More info...")."</a>)" ) . " (<a href='https://tt-rss.org/wiki/FeedHandlerPlugins' target='_blank'>".__("More info...")."</a>)"
); );
} }
@ -1067,9 +1067,7 @@ class Pref_Prefs extends Handler_Protected {
} }
} }
$rv = array_values(array_filter($rv, function ($item) { $rv = array_values(array_filter($rv, fn($item) => $item["rv"]["need_update"]));
return $item["rv"]["need_update"];
}));
return $rv; return $rv;
} }

View File

@ -39,7 +39,7 @@ class RSSUtils {
// check icon files once every Config::get(Config::CACHE_MAX_DAYS) days // check icon files once every Config::get(Config::CACHE_MAX_DAYS) days
$icon_files = array_filter(glob(Config::get(Config::ICONS_DIR) . "/*.ico"), $icon_files = array_filter(glob(Config::get(Config::ICONS_DIR) . "/*.ico"),
function($f) { return filemtime($f) < time() - 86400 * Config::get(Config::CACHE_MAX_DAYS); }); fn($f) => filemtime($f) < time() - 86400 * Config::get(Config::CACHE_MAX_DAYS));
foreach ($icon_files as $icon) { foreach ($icon_files as $icon) {
$feed_id = basename($icon, ".ico"); $feed_id = basename($icon, ".ico");
@ -865,7 +865,7 @@ class RSSUtils {
$pluginhost->run_hooks(PluginHost::HOOK_FILTER_TRIGGERED, $pluginhost->run_hooks(PluginHost::HOOK_FILTER_TRIGGERED,
$feed, $feed_obj->owner_uid, $article, $matched_filters, $matched_rules, $article_filters); $feed, $feed_obj->owner_uid, $article, $matched_filters, $matched_rules, $article_filters);
$matched_filter_ids = array_map(function($f) { return $f['id']; }, $matched_filters); $matched_filter_ids = array_map(fn($f) => $f['id'], $matched_filters);
if (count($matched_filter_ids) > 0) { if (count($matched_filter_ids) > 0) {
$filter_objs = ORM::for_table('ttrss_filters2') $filter_objs = ORM::for_table('ttrss_filters2')
@ -1801,7 +1801,7 @@ class RSSUtils {
[$cat_id]); [$cat_id]);
$check_cats_str = join(",", $check_cats); $check_cats_str = join(",", $check_cats);
$check_cats_fullids = array_map(function($a) { return "CAT:$a"; }, $check_cats); $check_cats_fullids = array_map(fn($a) => "CAT:$a", $check_cats);
while ($line = $sth->fetch()) { while ($line = $sth->fetch()) {
$filter_id = $line["id"]; $filter_id = $line["id"];