From 495e377d5b6c66e9783d1f7202e7def155ec482d Mon Sep 17 00:00:00 2001 From: jblairy Date: Fri, 28 Aug 2026 14:37:59 +0200 Subject: [PATCH] [CodingStyle] Skip callee arity mismatch on ArrowFunctionDelegatingCallToFirstClassCallableRector MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes a silent behavior change: the rule converts a 0-arity arrow function delegating to a method with an unused optional parameter into a first-class callable, which then forwards any extra argument the produced callable is invoked with — the original arrow function silently ignored it. --- ...zero_arity_optional_param_on_callee.php.inc | 18 ++++++++++++++++++ ...nctionAndClosureFirstClassCallableGuard.php | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 rules-tests/CodingStyle/Rector/ArrowFunction/ArrowFunctionDelegatingCallToFirstClassCallableRector/Fixture/skip_zero_arity_optional_param_on_callee.php.inc diff --git a/rules-tests/CodingStyle/Rector/ArrowFunction/ArrowFunctionDelegatingCallToFirstClassCallableRector/Fixture/skip_zero_arity_optional_param_on_callee.php.inc b/rules-tests/CodingStyle/Rector/ArrowFunction/ArrowFunctionDelegatingCallToFirstClassCallableRector/Fixture/skip_zero_arity_optional_param_on_callee.php.inc new file mode 100644 index 00000000000..5ea6ad6c332 --- /dev/null +++ b/rules-tests/CodingStyle/Rector/ArrowFunction/ArrowFunctionDelegatingCallToFirstClassCallableRector/Fixture/skip_zero_arity_optional_param_on_callee.php.inc @@ -0,0 +1,18 @@ +apply($callback ?? fn () => FooBar::optionalArgs()); + } + + private function apply(callable $callback) + { + return $callback('not optional-args input'); + } +} diff --git a/rules/CodingStyle/Guard/ArrowFunctionAndClosureFirstClassCallableGuard.php b/rules/CodingStyle/Guard/ArrowFunctionAndClosureFirstClassCallableGuard.php index 9cea1b90e14..6c58fc97f4a 100644 --- a/rules/CodingStyle/Guard/ArrowFunctionAndClosureFirstClassCallableGuard.php +++ b/rules/CodingStyle/Guard/ArrowFunctionAndClosureFirstClassCallableGuard.php @@ -117,7 +117,7 @@ public function shouldSkip( return false; } - return count($parameters) > 1; + return count($parameters) !== count($args); } private function isBuiltinReflection(FunctionReflection|MethodReflection $reflection): bool