From 2723dfd4df1f6c3f7a56afbbc211e0b63289bfd7 Mon Sep 17 00:00:00 2001 From: rajyan <38206553+rajyan@users.noreply.github.com> Date: Sat, 19 Jun 2021 22:55:49 +0900 Subject: [PATCH] [Php80] Fix OptionalParametersAfterRequiredRector to treat variadic as optional (#248) Co-authored-by: Alies Lapatsin --- .../treat_variadic_parameter_as_optional.php.inc | 11 +++++++++++ .../NodeResolver/RequireOptionalParamResolver.php | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 rules-tests/Php80/Rector/ClassMethod/OptionalParametersAfterRequiredRector/Fixture/treat_variadic_parameter_as_optional.php.inc diff --git a/rules-tests/Php80/Rector/ClassMethod/OptionalParametersAfterRequiredRector/Fixture/treat_variadic_parameter_as_optional.php.inc b/rules-tests/Php80/Rector/ClassMethod/OptionalParametersAfterRequiredRector/Fixture/treat_variadic_parameter_as_optional.php.inc new file mode 100644 index 00000000000..cab49025610 --- /dev/null +++ b/rules-tests/Php80/Rector/ClassMethod/OptionalParametersAfterRequiredRector/Fixture/treat_variadic_parameter_as_optional.php.inc @@ -0,0 +1,11 @@ +products = $products; + return $cart; + } +} diff --git a/rules/Php80/NodeResolver/RequireOptionalParamResolver.php b/rules/Php80/NodeResolver/RequireOptionalParamResolver.php index 78587360984..3cf47a0f8dc 100644 --- a/rules/Php80/NodeResolver/RequireOptionalParamResolver.php +++ b/rules/Php80/NodeResolver/RequireOptionalParamResolver.php @@ -19,7 +19,7 @@ public function resolve(FunctionLike $functionLike): array $optionalParams = []; $requireParams = []; foreach ($functionLike->getParams() as $position => $param) { - if ($param->default === null) { + if ($param->default === null && ! $param->variadic) { $requireParams[$position] = $param; } else { $optionalParams[$position] = $param;