Skip to content

Commit

Permalink
[CodingStyle] Skip anonymous class on MakeInheritedMethodVisibilitySa…
Browse files Browse the repository at this point in the history
…meAsParentRector (#5688)

* [CodingStyle] Skip anonymous class on MakeInheritedMethodVisibilitySameAsParentRector

* fix
  • Loading branch information
samsonasik committed Mar 4, 2024
1 parent 7df4894 commit 8c52d61
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
@@ -0,0 +1,20 @@
<?php

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

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

class SkipAnonymousClass
{
public function run()
{
$obj = new class extends ParentWithProtectedMethod {
public function run()
{
return 1;
}
};

var_dump($obj->run() === 1);
}
}
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

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

class ParentWithProtectedMethod
{
protected function run()
{
}
}
Expand Up @@ -85,6 +85,10 @@ public function refactor(Node $node): ?Node
return null;
}

if ($classReflection->isAnonymous()) {
return null;
}

$parentClassReflections = $classReflection->getParents();

if ($parentClassReflections === []) {
Expand Down

0 comments on commit 8c52d61

Please sign in to comment.