Merge pull request #18087 from kamil-tekiela/Short-closures
Use short closures where possible
This commit is contained in:
commit
2801ece589
@ -71,89 +71,48 @@ class Advisor
|
||||
'round',
|
||||
static function (): void {
|
||||
},
|
||||
/**
|
||||
* @param array $arguments
|
||||
* @param float $num
|
||||
*/
|
||||
static function ($arguments, $num) {
|
||||
return round($num);
|
||||
}
|
||||
static fn (array $arguments, float $num) => round($num)
|
||||
);
|
||||
$this->expression->register(
|
||||
'substr',
|
||||
static function (): void {
|
||||
},
|
||||
/**
|
||||
* @param array $arguments
|
||||
* @param string $string
|
||||
* @param int $start
|
||||
* @param int $length
|
||||
*/
|
||||
static function ($arguments, $string, $start, $length) {
|
||||
return substr($string, $start, $length);
|
||||
}
|
||||
static fn (array $arguments, string $string, int $start, int $length) => substr($string, $start, $length)
|
||||
);
|
||||
$this->expression->register(
|
||||
'preg_match',
|
||||
static function (): void {
|
||||
},
|
||||
/**
|
||||
* @param array $arguments
|
||||
* @param string $pattern
|
||||
* @param string $subject
|
||||
*/
|
||||
static function ($arguments, $pattern, $subject) {
|
||||
return preg_match($pattern, $subject);
|
||||
}
|
||||
static fn (array $arguments, string $pattern, string $subject) => preg_match($pattern, $subject)
|
||||
);
|
||||
$this->expression->register(
|
||||
'ADVISOR_bytime',
|
||||
static function (): void {
|
||||
},
|
||||
/**
|
||||
* @param array $arguments
|
||||
* @param float $num
|
||||
* @param int $precision
|
||||
*/
|
||||
static function ($arguments, $num, $precision) {
|
||||
return self::byTime($num, $precision);
|
||||
}
|
||||
static fn (array $arguments, float $num, int $precision) => self::byTime($num, $precision)
|
||||
);
|
||||
$this->expression->register(
|
||||
'ADVISOR_timespanFormat',
|
||||
static function (): void {
|
||||
},
|
||||
/**
|
||||
* @param array $arguments
|
||||
* @param string $seconds
|
||||
*/
|
||||
static function ($arguments, $seconds) {
|
||||
return Util::timespanFormat((int) $seconds);
|
||||
}
|
||||
static fn (array $arguments, string $seconds) => Util::timespanFormat((int) $seconds)
|
||||
);
|
||||
$this->expression->register(
|
||||
'ADVISOR_formatByteDown',
|
||||
static function (): void {
|
||||
},
|
||||
/**
|
||||
* @param array $arguments
|
||||
* @param int $value
|
||||
* @param int $limes
|
||||
* @param int $comma
|
||||
*/
|
||||
static function ($arguments, $value, $limes = 6, $comma = 0) {
|
||||
return implode(' ', (array) Util::formatByteDown($value, $limes, $comma));
|
||||
}
|
||||
static fn (
|
||||
array $arguments,
|
||||
int $value,
|
||||
int $limes = 6,
|
||||
int $comma = 0
|
||||
) => implode(' ', (array) Util::formatByteDown($value, $limes, $comma))
|
||||
);
|
||||
$this->expression->register(
|
||||
'fired',
|
||||
static function (): void {
|
||||
},
|
||||
/**
|
||||
* @param array $arguments
|
||||
* @param int $value
|
||||
*/
|
||||
function ($arguments, $value) {
|
||||
function (array $arguments, int $value) {
|
||||
// Did matching rule fire?
|
||||
foreach ($this->runResult['fired'] as $rule) {
|
||||
if ($rule['id'] == $value) {
|
||||
@ -345,25 +304,19 @@ class Advisor
|
||||
// linking to /server/variables
|
||||
$rule['recommendation'] = preg_replace_callback(
|
||||
'/\{([a-z_0-9]+)\}/Ui',
|
||||
function (array $matches) {
|
||||
return $this->replaceVariable($matches);
|
||||
},
|
||||
fn (array $matches) => $this->replaceVariable($matches),
|
||||
$rule['recommendation']
|
||||
);
|
||||
$rule['issue'] = preg_replace_callback(
|
||||
'/\{([a-z_0-9]+)\}/Ui',
|
||||
function (array $matches) {
|
||||
return $this->replaceVariable($matches);
|
||||
},
|
||||
fn (array $matches) => $this->replaceVariable($matches),
|
||||
$rule['issue']
|
||||
);
|
||||
|
||||
// Replaces external Links with Core::linkURL() generated links
|
||||
$rule['recommendation'] = preg_replace_callback(
|
||||
'#href=("|\')(https?://[^"\']+)\1#i',
|
||||
function (array $matches) {
|
||||
return $this->replaceLinkURL($matches);
|
||||
},
|
||||
fn (array $matches) => $this->replaceLinkURL($matches),
|
||||
$rule['recommendation']
|
||||
);
|
||||
|
||||
|
||||
@ -395,9 +395,7 @@ class Config
|
||||
*/
|
||||
$cfg = array_filter(
|
||||
$cfg,
|
||||
static function (string $key): bool {
|
||||
return ! str_contains($key, '/');
|
||||
},
|
||||
static fn (string $key): bool => ! str_contains($key, '/'),
|
||||
ARRAY_FILTER_USE_KEY
|
||||
);
|
||||
|
||||
|
||||
@ -486,9 +486,7 @@ class DatabaseInterface implements DbalInterface
|
||||
. implode(
|
||||
', ',
|
||||
array_map(
|
||||
function (string $string) use ($connectionType): string {
|
||||
return $this->quoteString($string, $connectionType);
|
||||
},
|
||||
fn (string $string): string => $this->quoteString($string, $connectionType),
|
||||
$table
|
||||
)
|
||||
) . ')';
|
||||
@ -753,9 +751,7 @@ class DatabaseInterface implements DbalInterface
|
||||
if ($applyLimitAndOrderManual) {
|
||||
usort(
|
||||
$databases,
|
||||
static function ($a, $b) use ($sortBy, $sortOrder) {
|
||||
return Utilities::usortComparisonCallback($a, $b, $sortBy, $sortOrder);
|
||||
}
|
||||
static fn ($a, $b) => Utilities::usortComparisonCallback($a, $b, $sortBy, $sortOrder)
|
||||
);
|
||||
|
||||
/**
|
||||
|
||||
@ -1310,9 +1310,7 @@ class Export
|
||||
);
|
||||
}
|
||||
|
||||
$postParams = array_filter($this->getPostParams($exportType), static function ($value) {
|
||||
return ! is_array($value);
|
||||
});
|
||||
$postParams = array_filter($this->getPostParams($exportType), static fn ($value) => ! is_array($value));
|
||||
$backButton .= '&' . http_build_query($postParams);
|
||||
|
||||
$backButton .= '&repopulate=1">' . __('Back') . '</a> ]</p>';
|
||||
|
||||
@ -711,7 +711,7 @@ class LanguageManager
|
||||
/** @var array */
|
||||
private $availableLocales;
|
||||
|
||||
/** @var array */
|
||||
/** @var Language[] */
|
||||
private $availableLanguages = [];
|
||||
|
||||
/** @var bool */
|
||||
@ -847,9 +847,7 @@ class LanguageManager
|
||||
public function sortedLanguages()
|
||||
{
|
||||
$this->availableLanguages();
|
||||
uasort($this->availableLanguages, static function (Language $a, Language $b) {
|
||||
return $a->cmp($b);
|
||||
});
|
||||
uasort($this->availableLanguages, static fn (Language $a, Language $b) => $a->cmp($b));
|
||||
|
||||
return $this->availableLanguages;
|
||||
}
|
||||
|
||||
@ -168,9 +168,10 @@ class Plugins
|
||||
}
|
||||
}
|
||||
|
||||
usort($plugins, static function (Plugin $plugin1, Plugin $plugin2): int {
|
||||
return strcasecmp($plugin1->getProperties()->getText(), $plugin2->getProperties()->getText());
|
||||
});
|
||||
usort($plugins, static fn (Plugin $plugin1, Plugin $plugin2): int => strcasecmp(
|
||||
$plugin1->getProperties()->getText(),
|
||||
$plugin2->getProperties()->getText()
|
||||
));
|
||||
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
@ -208,17 +208,17 @@ class Sanitize
|
||||
$pattern = '/\[a@([^]"@]*)(@([^]"]*))?\]/';
|
||||
|
||||
/* Find and replace all links */
|
||||
$message = (string) preg_replace_callback($pattern, static function (array $match) {
|
||||
return self::replaceBBLink($match);
|
||||
}, $message);
|
||||
$message = (string) preg_replace_callback(
|
||||
$pattern,
|
||||
static fn (array $match) => self::replaceBBLink($match),
|
||||
$message
|
||||
);
|
||||
|
||||
/* Replace documentation links */
|
||||
$message = (string) preg_replace_callback(
|
||||
'/\[doc@([a-zA-Z0-9_-]+)(@([a-zA-Z0-9_-]*))?\]/',
|
||||
/** @param string[] $match */
|
||||
static function (array $match): string {
|
||||
return self::replaceDocLink($match);
|
||||
},
|
||||
static fn (array $match): string => self::replaceDocLink($match),
|
||||
$message
|
||||
);
|
||||
|
||||
|
||||
@ -259,12 +259,8 @@ class Privileges
|
||||
$grantCols = array_map(
|
||||
/**
|
||||
* @param string $val
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function ($val) {
|
||||
return Util::backquote($val);
|
||||
},
|
||||
static fn ($val): string => Util::backquote($val),
|
||||
$GLOBALS[$currentGrant[0]]
|
||||
);
|
||||
|
||||
|
||||
@ -111,11 +111,9 @@ class StorageEngine
|
||||
$disabled = (string) SessionCache::get(
|
||||
'disabled_storage_engines',
|
||||
/** @return mixed|false */
|
||||
static function () {
|
||||
return $GLOBALS['dbi']->fetchValue(
|
||||
'SELECT @@disabled_storage_engines'
|
||||
);
|
||||
}
|
||||
static fn () => $GLOBALS['dbi']->fetchValue(
|
||||
'SELECT @@disabled_storage_engines'
|
||||
)
|
||||
);
|
||||
foreach (explode(',', $disabled) as $engine) {
|
||||
if (! isset($storage_engines[$engine])) {
|
||||
|
||||
@ -20,23 +20,17 @@ class MessageExtension extends AbstractExtension
|
||||
return [
|
||||
new TwigFilter(
|
||||
'notice',
|
||||
static function (string $string) {
|
||||
return Message::notice($string)->getDisplay();
|
||||
},
|
||||
static fn (string $string) => Message::notice($string)->getDisplay(),
|
||||
['is_safe' => ['html']]
|
||||
),
|
||||
new TwigFilter(
|
||||
'error',
|
||||
static function (string $string) {
|
||||
return Message::error($string)->getDisplay();
|
||||
},
|
||||
static fn (string $string) => Message::error($string)->getDisplay(),
|
||||
['is_safe' => ['html']]
|
||||
),
|
||||
new TwigFilter(
|
||||
'raw_success',
|
||||
static function (string $string) {
|
||||
return Message::rawSuccess($string)->getDisplay();
|
||||
},
|
||||
static fn (string $string) => Message::rawSuccess($string)->getDisplay(),
|
||||
['is_safe' => ['html']]
|
||||
),
|
||||
];
|
||||
|
||||
@ -2522,9 +2522,7 @@ class Util
|
||||
$disabled = ini_get('disable_functions');
|
||||
if (is_string($disabled)) {
|
||||
$disabled = explode(',', $disabled);
|
||||
$disabled = array_map(static function (string $part) {
|
||||
return trim($part);
|
||||
}, $disabled);
|
||||
$disabled = array_map(static fn (string $part) => trim($part), $disabled);
|
||||
|
||||
return ! in_array('error_reporting', $disabled);
|
||||
}
|
||||
|
||||
@ -82,9 +82,9 @@ final class WebauthnLibServer implements Server
|
||||
$server = new WebauthnServer($relyingPartyEntity, $publicKeyCredentialSourceRepository);
|
||||
$credentialSources = $publicKeyCredentialSourceRepository->findAllForUserEntity($userEntity);
|
||||
$allowedCredentials = array_map(
|
||||
static function (PublicKeyCredentialSource $credential): PublicKeyCredentialDescriptor {
|
||||
return $credential->getPublicKeyCredentialDescriptor();
|
||||
},
|
||||
static fn (
|
||||
PublicKeyCredentialSource $credential
|
||||
): PublicKeyCredentialDescriptor => $credential->getPublicKeyCredentialDescriptor(),
|
||||
$credentialSources
|
||||
);
|
||||
$publicKeyCredentialRequestOptions = $server->generatePublicKeyCredentialRequestOptions(
|
||||
|
||||
@ -5285,11 +5285,6 @@ parameters:
|
||||
count: 1
|
||||
path: libraries/classes/LanguageManager.php
|
||||
|
||||
-
|
||||
message: "#^Property PhpMyAdmin\\\\LanguageManager\\:\\:\\$availableLanguages type has no value type specified in iterable type array\\.$#"
|
||||
count: 1
|
||||
path: libraries/classes/LanguageManager.php
|
||||
|
||||
-
|
||||
message: "#^Property PhpMyAdmin\\\\LanguageManager\\:\\:\\$availableLocales \\(array\\) does not accept array\\|false\\.$#"
|
||||
count: 1
|
||||
|
||||
@ -9549,9 +9549,6 @@
|
||||
</MixedArgument>
|
||||
<MixedArgumentTypeCoercion>
|
||||
<code>$this->listLocaleDir()</code>
|
||||
<code>uasort($this->availableLanguages, static function (Language $a, Language $b) {
|
||||
return $a->cmp($b);
|
||||
})</code>
|
||||
</MixedArgumentTypeCoercion>
|
||||
<MixedArrayOffset>
|
||||
<code>$langs[$GLOBALS['config']->get('DefaultLang')]</code>
|
||||
@ -9564,21 +9561,9 @@
|
||||
<MixedAssignment>
|
||||
<code>$lang</code>
|
||||
</MixedAssignment>
|
||||
<MixedInferredReturnType>
|
||||
<code>Language</code>
|
||||
</MixedInferredReturnType>
|
||||
<MixedOperand>
|
||||
<code>$GLOBALS['config']->get('FilterLanguages')</code>
|
||||
</MixedOperand>
|
||||
<MixedReturnStatement>
|
||||
<code>$this->availableLanguages[strtolower($GLOBALS['lang'])]</code>
|
||||
</MixedReturnStatement>
|
||||
<MixedReturnTypeCoercion>
|
||||
<code>$this->availableLanguages</code>
|
||||
<code>$this->availableLanguages</code>
|
||||
<code>Language[]</code>
|
||||
<code>Language[]</code>
|
||||
</MixedReturnTypeCoercion>
|
||||
<PossiblyInvalidArgument>
|
||||
<code>$_GET['lang']</code>
|
||||
<code>$_POST['lang']</code>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user