Use arrow functions

This commit is contained in:
Giuseppe Criscione 2021-07-07 18:13:07 +02:00
parent 7c5c7e9100
commit 70f4f7def3
9 changed files with 10 additions and 30 deletions

View File

@ -1,7 +1,5 @@
<?php
return [
'assets' => static function () {
return \Formwork\Formwork::instance()->admin()->assets();
}
'assets' => static fn () => \Formwork\Formwork::instance()->admin()->assets()
];

View File

@ -4,9 +4,7 @@ return [
'routes' => [
'admin.index' => [
'path' => '/',
'action' => function () {
return \Formwork\Formwork::instance()->admin()->redirect('/dashboard/');
}
'action' => fn () => \Formwork\Formwork::instance()->admin()->redirect('/dashboard/')
],
'admin.login' => [
'path' => '/login/',

View File

@ -56,7 +56,5 @@ return [
\Formwork\Formwork::instance()->config()->get('date.format') . ' ' . \Formwork\Formwork::instance()->config()->get('date.time_format')
);
},
'translate' => static function (string $key, ...$arguments) {
return \Formwork\Formwork::instance()->translations()->getCurrent()->translate($key, ...$arguments);
}
'translate' => static fn (string $key, ...$arguments) => \Formwork\Formwork::instance()->translations()->getCurrent()->translate($key, ...$arguments)
];

View File

@ -132,9 +132,7 @@ class Statistics
$visits = array_slice($visits, -$limit, null, true);
$uniqueVisits = array_slice($uniqueVisits, -$limit, null, true);
$labels = array_map(static function (string $day): string {
return Date::formatTimestamp(Date::toTimestamp($day, self::DATE_FORMAT), "D\nj M");
}, $days);
$labels = array_map(static fn (string $day): string => Date::formatTimestamp(Date::toTimestamp($day, self::DATE_FORMAT), "D\nj M"), $days);
$interpolate = static function (array $data) use ($days): array {
$output = [];

View File

@ -68,9 +68,7 @@ class Translator
protected static function interpolate($value)
{
if (is_array($value)) {
return array_map(static function ($value) {
return static::interpolate($value);
}, $value);
return array_map(static fn ($value) => static::interpolate($value), $value);
}
if (is_string($value) && (bool) preg_match(self::INTERPOLATION_REGEX, $value, $matches)) {
return Formwork::instance()->translations()->getCurrent()->translate($matches[1]);

View File

@ -177,9 +177,7 @@ class Validator
}
if ($field->has('pattern')) {
$value = array_filter($value, static function ($item) use ($field): bool {
return static::regex($item, $field->get('pattern'));
});
$value = array_filter($value, static fn ($item): bool => static::regex($item, $field->get('pattern')));
}
return array_values(array_filter($value));

View File

@ -13,9 +13,7 @@ class Files extends AssociativeCollection
public function filterByType(string $type): self
{
$files = clone $this;
$files->items = array_filter($files->items, static function (File $item) use ($type): bool {
return $item->type() === $type;
});
$files->items = array_filter($files->items, static fn (File $item): bool => $item->type() === $type);
return $files;
}

View File

@ -131,9 +131,7 @@ class PageCollection extends Collection
throw new InvalidArgumentException('Invalid sorting direction. Use SORT_ASC or 1 for ascending order, SORT_DESC or -1 for descending');
}
usort($pageCollection->items, static function (Page $item1, Page $item2) use ($property, $direction): int {
return $direction * strnatcasecmp($item1->get($property), $item2->get($property));
});
usort($pageCollection->items, static fn (Page $item1, Page $item2): int => $direction * strnatcasecmp($item1->get($property), $item2->get($property)));
return $pageCollection;
}
@ -163,9 +161,7 @@ class PageCollection extends Collection
$keywords = explode(' ', $query);
$keywords = array_diff($keywords, (array) Formwork::instance()->config()->get('search.stopwords'));
$keywords = array_filter($keywords, static function (string $item) use ($min): bool {
return strlen($item) > $min;
});
$keywords = array_filter($keywords, static fn (string $item): bool => strlen($item) > $min);
$queryRegex = '/\b' . preg_quote($query, '/') . '\b/iu';
$keywordsRegex = '/(?:\b' . implode('\b|\b', $keywords) . '\b)/iu';

View File

@ -123,9 +123,7 @@ class HTTPClient
if (($handle = @fopen($uri, 'r', false, $context)) === false) {
$messages = implode("\n", array_map(
static function (int $i, array $error): string {
return sprintf('#%d %s', $i, str_replace("\n", ' ', $error['message']));
},
static fn (int $i, array $error): string => sprintf('#%d %s', $i, str_replace("\n", ' ', $error['message'])),
array_keys($errors),
$errors
));