mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-25 01:39:49 +01:00
fix args miss-match in RemoveDelegatingParentCallRector (#1832)
fix args miss-match in RemoveDelegatingParentCallRector
This commit is contained in:
commit
af193ba355
@ -109,11 +109,34 @@ CODE_SAMPLE
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DeadCode\Tests\Rector\ClassMethod\RemoveDelegatingParentCallRector\Fixture;
|
||||
|
||||
final class SkipExtraArguments extends \Exception
|
||||
{
|
||||
public function __construct(string $parameter)
|
||||
{
|
||||
parent::__construct(
|
||||
sprintf('Request parameter (%s) is not valid.', $parameter)
|
||||
);
|
||||
}
|
||||
|
||||
public function run(string $parameter)
|
||||
{
|
||||
parent::run($parameter . '_');
|
||||
}
|
||||
}
|
@ -12,6 +12,8 @@ final class RemoveDelegatingParentCallRectorTest extends AbstractRectorTestCase
|
||||
$this->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',
|
||||
|
Loading…
x
Reference in New Issue
Block a user