[Php71] Skip interface type on RemoveExtraParametersRector (#237)

This commit is contained in:
Abdul Malik Ikhsan 2021-06-17 22:52:59 +07:00 committed by GitHub
parent 246a5863ed
commit 1fb8e54d95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,22 @@
<?php
namespace Rector\Tests\Php71\Rector\FuncCall\RemoveExtraParametersRector\Fixture;
use Rector\Tests\Php71\Rector\FuncCall\RemoveExtraParametersRector\Source\CollectionInterface;
use Rector\Tests\Php71\Rector\FuncCall\RemoveExtraParametersRector\Source\CollectionImpl;
final class SkipInterfaceType
{
/** @var CollectionInterface*/
private $collection;
public function __construct()
{
$this->collection = new CollectionImpl();
}
public function run()
{
$this->collection->getData('value');
}
}

View File

@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace Rector\Tests\Php71\Rector\FuncCall\RemoveExtraParametersRector\Source;
class CollectionImpl implements CollectionInterface
{
public function getData(string $var = null)
{
echo $var ?? 'fallback';
}
}

View File

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Rector\Tests\Php71\Rector\FuncCall\RemoveExtraParametersRector\Source;
interface CollectionInterface
{
public function getData();
}

View File

@ -12,6 +12,7 @@ use PhpParser\Node\Name;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ParametersAcceptor;
use PHPStan\Reflection\Php\PhpMethodReflection;
use PHPStan\Reflection\Type\UnionTypeMethodReflection;
use Rector\Core\PHPStan\Reflection\CallReflectionResolver;
use Rector\Core\Rector\AbstractRector;
@ -65,6 +66,13 @@ final class RemoveExtraParametersRector extends AbstractRector
return null;
}
if ($functionLikeReflection instanceof PhpMethodReflection) {
$classReflection = $functionLikeReflection->getDeclaringClass();
if ($classReflection->isInterface()) {
return null;
}
}
$maximumAllowedParameterCount = $this->resolveMaximumAllowedParameterCount($functionLikeReflection);
$numberOfArguments = count($node->args);