Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodingStyle] Skip implements interface on MakeInheritedMethodVisibilitySameAsParentRector #5707

Merged
merged 4 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Rector\Tests\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector\Fixture;

use Rector\Tests\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector\Source\ParentWithProtectedMethod;
use Rector\Tests\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector\Source\SomeInterface;

final class SkipImplementsInterface extends ParentWithProtectedMethod implements SomeInterface
{
public function run()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector\Source;

interface SomeInterface
{
public function run();
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function refactor(Node $node): ?Node
}

$hasChanged = false;
$interfaces = $classReflection->getInterfaces();

foreach ($node->getMethods() as $classMethod) {
if ($classMethod->isMagic()) {
Expand All @@ -105,6 +106,12 @@ public function refactor(Node $node): ?Node
/** @var string $methodName */
$methodName = $this->getName($classMethod->name);

foreach ($interfaces as $interface) {
if ($interface->hasNativeMethod($methodName)) {
continue 2;
}
}

foreach ($parentClassReflections as $parentClassReflection) {
$nativeClassReflection = $parentClassReflection->getNativeReflection();

Expand Down