From 5b536131f720e5df8fca42a93a17d1169efd55f8 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Thu, 11 Feb 2021 20:34:41 +0100 Subject: [PATCH] Modernize func_get_args() calls to variadic parameters --- .../Component/ExpressionLanguage/ExpressionFunction.php | 8 ++++---- src/Symfony/Component/Filesystem/Filesystem.php | 6 ++++-- .../Component/Intl/Tests/Locale/AbstractLocaleTest.php | 7 ++++++- src/Symfony/Component/Intl/Tests/Locale/LocaleTest.php | 4 +--- .../Intl/Tests/Locale/Verification/LocaleTest.php | 4 +--- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Symfony/Component/ExpressionLanguage/ExpressionFunction.php b/src/Symfony/Component/ExpressionLanguage/ExpressionFunction.php index 2bc91e8d03..18d81ecda0 100644 --- a/src/Symfony/Component/ExpressionLanguage/ExpressionFunction.php +++ b/src/Symfony/Component/ExpressionLanguage/ExpressionFunction.php @@ -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); diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 4053d9e6a5..b5eb6b5c3b 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -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; diff --git a/src/Symfony/Component/Intl/Tests/Locale/AbstractLocaleTest.php b/src/Symfony/Component/Intl/Tests/Locale/AbstractLocaleTest.php index cf991c9bcc..a3daecb59e 100644 --- a/src/Symfony/Component/Intl/Tests/Locale/AbstractLocaleTest.php +++ b/src/Symfony/Component/Intl/Tests/Locale/AbstractLocaleTest.php @@ -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); } diff --git a/src/Symfony/Component/Intl/Tests/Locale/LocaleTest.php b/src/Symfony/Component/Intl/Tests/Locale/LocaleTest.php index 80b3352e21..05ba7106eb 100644 --- a/src/Symfony/Component/Intl/Tests/Locale/LocaleTest.php +++ b/src/Symfony/Component/Intl/Tests/Locale/LocaleTest.php @@ -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); } } diff --git a/src/Symfony/Component/Intl/Tests/Locale/Verification/LocaleTest.php b/src/Symfony/Component/Intl/Tests/Locale/Verification/LocaleTest.php index 45c90f6c0f..c0b1b26b62 100644 --- a/src/Symfony/Component/Intl/Tests/Locale/Verification/LocaleTest.php +++ b/src/Symfony/Component/Intl/Tests/Locale/Verification/LocaleTest.php @@ -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); } }