diff --git a/packages/DeadCode/src/Rector/ClassMethod/RemoveDelegatingParentCallRector.php b/packages/DeadCode/src/Rector/ClassMethod/RemoveDelegatingParentCallRector.php index d4c512b6e9f3..725003383cec 100644 --- a/packages/DeadCode/src/Rector/ClassMethod/RemoveDelegatingParentCallRector.php +++ b/packages/DeadCode/src/Rector/ClassMethod/RemoveDelegatingParentCallRector.php @@ -109,11 +109,34 @@ private function isParentCallMatching(ClassMethod $classMethod, ?StaticCall $sta return false; } - // are arguments the same? - if (count($staticCall->args) !== count($classMethod->params)) { + if (! $this->areArgsAndParamsEqual($staticCall->args, $classMethod->params)) { return false; } return true; } + + /** + * @param Node\Arg[] $args + * @param Node\Param[] $params + */ + private function areArgsAndParamsEqual(array $args, array $params): bool + { + if (count($args) !== count($params)) { + return false; + } + + foreach ($args as $key => $arg) { + if (! isset($params[$key])) { + return false; + } + + $param = $params[$key]; + if (! $this->areNamesEqual($param->var, $arg->value)) { + return false; + } + } + + return true; + } } diff --git a/packages/DeadCode/tests/Rector/ClassMethod/RemoveDelegatingParentCallRector/Fixture/skip_extra_arguments.php.inc b/packages/DeadCode/tests/Rector/ClassMethod/RemoveDelegatingParentCallRector/Fixture/skip_extra_arguments.php.inc new file mode 100644 index 000000000000..f5aa337996d4 --- /dev/null +++ b/packages/DeadCode/tests/Rector/ClassMethod/RemoveDelegatingParentCallRector/Fixture/skip_extra_arguments.php.inc @@ -0,0 +1,18 @@ +doTestFiles([ __DIR__ . '/Fixture/fixture.php.inc', __DIR__ . '/Fixture/in_trait.php.inc', + // skip + __DIR__ . '/Fixture/skip_extra_arguments.php.inc', __DIR__ . '/Fixture/skip_extra_content.php.inc', __DIR__ . '/Fixture/skip_different_method_name.php.inc', __DIR__ . '/Fixture/skip_changed_arguments.php.inc',