From f79875ccafefd94f10204eefb13effdab958e30a Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 23 Jul 2025 14:29:01 +0200 Subject: [PATCH 1/2] NarrowPrivateClassMethodParamTypeRule: Skip variadics --- .../NarrowPrivateClassMethodParamTypeRule.php | 4 ++++ .../Fixture/SkipVariadics.php | 22 +++++++++++++++++++ ...rowPrivateClassMethodParamTypeRuleTest.php | 1 + 3 files changed, 27 insertions(+) create mode 100644 tests/Rules/NarrowPrivateClassMethodParamTypeRule/Fixture/SkipVariadics.php diff --git a/src/Rules/NarrowPrivateClassMethodParamTypeRule.php b/src/Rules/NarrowPrivateClassMethodParamTypeRule.php index 4c8d82e6..f81cacc2 100644 --- a/src/Rules/NarrowPrivateClassMethodParamTypeRule.php +++ b/src/Rules/NarrowPrivateClassMethodParamTypeRule.php @@ -110,6 +110,10 @@ private function validateArgVsParamTypes(array $args, MethodCall $methodCall, Sc continue; } + if ($param->variadic) { + return []; + } + $paramRuleError = $this->validateParam($param, $position, $arg->value, $scope); if (! $paramRuleError instanceof RuleError) { continue; diff --git a/tests/Rules/NarrowPrivateClassMethodParamTypeRule/Fixture/SkipVariadics.php b/tests/Rules/NarrowPrivateClassMethodParamTypeRule/Fixture/SkipVariadics.php new file mode 100644 index 00000000..2e55c19b --- /dev/null +++ b/tests/Rules/NarrowPrivateClassMethodParamTypeRule/Fixture/SkipVariadics.php @@ -0,0 +1,22 @@ +takesVariadic(...$arr); + } + + private function takesVariadic(Node ...$node) + { + + } +} diff --git a/tests/Rules/NarrowPrivateClassMethodParamTypeRule/NarrowPrivateClassMethodParamTypeRuleTest.php b/tests/Rules/NarrowPrivateClassMethodParamTypeRule/NarrowPrivateClassMethodParamTypeRuleTest.php index 1005cc1d..84483443 100644 --- a/tests/Rules/NarrowPrivateClassMethodParamTypeRule/NarrowPrivateClassMethodParamTypeRuleTest.php +++ b/tests/Rules/NarrowPrivateClassMethodParamTypeRule/NarrowPrivateClassMethodParamTypeRuleTest.php @@ -50,6 +50,7 @@ public static function provideData(): Iterator yield [__DIR__ . '/Fixture/DoubleShot.php', [[$argErrorMessage, 15], [$paramErrorMessage, 15]]]; yield [__DIR__ . '/Fixture/SkipGenericType.php', []]; yield [__DIR__ . '/Fixture/SkipAbstractBase.php', []]; + yield [__DIR__ . '/Fixture/SkipVariadics.php', []]; } /** From da26baf003e0a6d0bab00563e67508eacc592da3 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 23 Jul 2025 14:31:49 +0200 Subject: [PATCH 2/2] remove unused import --- .../Fixture/SkipVariadics.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Rules/NarrowPrivateClassMethodParamTypeRule/Fixture/SkipVariadics.php b/tests/Rules/NarrowPrivateClassMethodParamTypeRule/Fixture/SkipVariadics.php index 2e55c19b..db8c922b 100644 --- a/tests/Rules/NarrowPrivateClassMethodParamTypeRule/Fixture/SkipVariadics.php +++ b/tests/Rules/NarrowPrivateClassMethodParamTypeRule/Fixture/SkipVariadics.php @@ -5,7 +5,6 @@ namespace Rector\TypePerfect\Tests\Rules\NarrowPrivateClassMethodParamTypeRule\Fixture; use PhpParser\Node; -use PhpParser\Node\Expr\MethodCall; class SkipVariadics {