diff --git a/rules/renaming/src/Rector/MethodCall/RenameMethodRector.php b/rules/renaming/src/Rector/MethodCall/RenameMethodRector.php index 267be8cd431..f45012cf818 100644 --- a/rules/renaming/src/Rector/MethodCall/RenameMethodRector.php +++ b/rules/renaming/src/Rector/MethodCall/RenameMethodRector.php @@ -13,6 +13,7 @@ use PhpParser\Node\Identifier; use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\ClassMethod; use Rector\Core\Contract\Rector\ConfigurableRectorInterface; +use Rector\Core\NodeManipulator\ClassManipulator; use Rector\Core\Rector\AbstractRector; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Renaming\Contract\MethodCallRenameInterface; @@ -37,6 +38,16 @@ final class RenameMethodRector extends AbstractRector implements ConfigurableRec */ private $methodCallRenames = []; + /** + * @var ClassManipulator + */ + private $classManipulator; + + public function __construct(ClassManipulator $classManipulator) + { + $this->classManipulator = $classManipulator; + } + public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Turns method names to new ones.', [ @@ -74,6 +85,14 @@ CODE_SAMPLE public function refactor(Node $node): ?Node { foreach ($this->methodCallRenames as $methodCallRename) { + $implementsInterface = $this->classManipulator->hasParentMethodOrInterface( + $methodCallRename->getOldClass(), + $methodCallRename->getOldMethod() + ); + if ($implementsInterface) { + continue; + } + if (! $this->nodeTypeResolver->isMethodStaticCallOrClassMethodObjectType( $node, $methodCallRename->getOldClass() diff --git a/rules/renaming/tests/Rector/MethodCall/RenameMethodRector/Fixture/skip_when_interface.php.inc b/rules/renaming/tests/Rector/MethodCall/RenameMethodRector/Fixture/skip_when_interface.php.inc new file mode 100644 index 00000000000..ea3211defba --- /dev/null +++ b/rules/renaming/tests/Rector/MethodCall/RenameMethodRector/Fixture/skip_when_interface.php.inc @@ -0,0 +1,26 @@ +old(); + } +} +?> diff --git a/rules/renaming/tests/Rector/MethodCall/RenameMethodRector/config/configured_rule.php b/rules/renaming/tests/Rector/MethodCall/RenameMethodRector/config/configured_rule.php index e477e13e0e9..4528d8fc668 100644 --- a/rules/renaming/tests/Rector/MethodCall/RenameMethodRector/config/configured_rule.php +++ b/rules/renaming/tests/Rector/MethodCall/RenameMethodRector/config/configured_rule.php @@ -20,6 +20,11 @@ return static function (ContainerConfigurator $containerConfigurator): void { 'notify', '__invoke' ), + new MethodCallRename( + 'Rector\Renaming\Tests\Rector\MethodCall\RenameMethodRector\Fixture\SomeSubscriber', + 'old', + 'new' + ), new MethodCallRename('*Presenter', 'run', '__invoke'), new MethodCallRename( \Rector\Renaming\Tests\Rector\MethodCall\RenameMethodRector\Fixture\SkipSelfMethodRename::class,