fix args miss-match in RemoveDelegatingParentCallRector (#1832)

fix args miss-match in RemoveDelegatingParentCallRector
This commit is contained in:
Tomáš Votruba 2019-08-09 11:23:02 +02:00 committed by GitHub
commit af193ba355
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 2 deletions

View File

@ -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;
}
}

View File

@ -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 . '_');
}
}

View File

@ -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',