Modernize func_get_args() calls to variadic parameters

This commit is contained in:
Alexander M. Turek 2021-02-11 20:34:41 +01:00
parent b22562f975
commit 5b536131f7
5 changed files with 16 additions and 13 deletions

View File

@ -85,12 +85,12 @@ class ExpressionFunction
throw new \InvalidArgumentException(sprintf('An expression function name must be defined when PHP function "%s" is namespaced.', $phpFunctionName));
}
$compiler = function () use ($phpFunctionName) {
return sprintf('\%s(%s)', $phpFunctionName, implode(', ', \func_get_args()));
$compiler = function (...$args) use ($phpFunctionName) {
return sprintf('\%s(%s)', $phpFunctionName, implode(', ', $args));
};
$evaluator = function () use ($phpFunctionName) {
return $phpFunctionName(...\array_slice(\func_get_args(), 1));
$evaluator = function ($p, ...$args) use ($phpFunctionName) {
return $phpFunctionName(...$args);
};
return new self($expressionFunctionName ?: end($parts), $compiler, $evaluator);

View File

@ -746,14 +746,16 @@ class Filesystem
}
/**
* @param mixed ...$args
*
* @return mixed
*/
private static function box(callable $func)
private static function box(callable $func, ...$args)
{
self::$lastError = null;
set_error_handler(__CLASS__.'::handleError');
try {
$result = $func(...\array_slice(\func_get_args(), 1));
$result = $func(...$args);
restore_error_handler();
return $result;

View File

@ -27,5 +27,10 @@ abstract class AbstractLocaleTest extends TestCase
$this->assertSame('en_GB', $this->call('getDefault'));
}
abstract protected function call($methodName);
/**
* @param mixed ...$args
*
* @return mixed
*/
abstract protected function call(string $methodName, ...$args);
}

View File

@ -139,10 +139,8 @@ class LocaleTest extends AbstractLocaleTest
$this->assertSame('en', $this->call('getDefault'));
}
protected function call($methodName)
protected function call(string $methodName, ...$args)
{
$args = \array_slice(\func_get_args(), 1);
return Locale::{$methodName}(...$args);
}
}

View File

@ -29,10 +29,8 @@ class LocaleTest extends AbstractLocaleTest
parent::setUp();
}
protected function call($methodName)
protected function call(string $methodName, ...$args)
{
$args = \array_slice(\func_get_args(), 1);
return \Locale::{$methodName}(...$args);
}
}