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

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

View File

@ -163,9 +163,7 @@ class Digest
$article_labels_formatted = "";
if (is_array($article_labels) && count($article_labels) > 0) {
$article_labels_formatted = implode(", ", array_map(function($a) {
return $a[1];
}, $article_labels));
$article_labels_formatted = implode(", ", array_map(fn($a) => $a[1], $article_labels));
}
$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_FETCH_FEED));
$feed_handlers = array_filter($feed_handlers, function($plugin) use ($feed_handler_whitelist) {
return in_array(get_class($plugin), $feed_handler_whitelist) === false; });
$feed_handlers = array_filter($feed_handlers,
fn($plugin) => in_array(get_class($plugin), $feed_handler_whitelist) === false);
if (count($feed_handlers) > 0) {
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>" ,
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>)"
);
}
@ -1067,9 +1067,7 @@ class Pref_Prefs extends Handler_Protected {
}
}
$rv = array_values(array_filter($rv, function ($item) {
return $item["rv"]["need_update"];
}));
$rv = array_values(array_filter($rv, fn($item) => $item["rv"]["need_update"]));
return $rv;
}

View File

@ -39,7 +39,7 @@ class RSSUtils {
// check icon files once every Config::get(Config::CACHE_MAX_DAYS) days
$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) {
$feed_id = basename($icon, ".ico");
@ -865,7 +865,7 @@ class RSSUtils {
$pluginhost->run_hooks(PluginHost::HOOK_FILTER_TRIGGERED,
$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) {
$filter_objs = ORM::for_table('ttrss_filters2')
@ -1801,7 +1801,7 @@ class RSSUtils {
[$cat_id]);
$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()) {
$filter_id = $line["id"];