Skip to content

Commit

Permalink
[DeadCode] Skip parent not found on RemoveParentCallWithoutParentRect…
Browse files Browse the repository at this point in the history
…or (#1510)

* [DeadCode] Skip parent not found on RemoveParentCallWithoutParentRector

* Fixed 🎉

* [ci-review] Rector Rectify

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
samsonasik and actions-user committed Dec 16, 2021
1 parent 6bd25c8 commit 4bac761
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Rector\Tests\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector\Fixture;

class A extends B
{
protected function run()
{
return parent::run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
use PhpParser\Node;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\ReflectionProvider;
use Rector\Core\Enum\ObjectReference;
use Rector\Core\NodeAnalyzer\ClassAnalyzer;
use Rector\Core\NodeManipulator\ClassMethodManipulator;
Expand All @@ -28,7 +30,8 @@ final class RemoveParentCallWithoutParentRector extends AbstractRector
public function __construct(
private readonly ClassMethodManipulator $classMethodManipulator,
private readonly ParentClassScopeResolver $parentClassScopeResolver,
private readonly ClassAnalyzer $classAnalyzer
private readonly ClassAnalyzer $classAnalyzer,
private readonly ReflectionProvider $reflectionProvider
) {
}

Expand Down Expand Up @@ -87,6 +90,12 @@ public function refactor(Node $node): ?Node
return null;
}

if ($classLike->extends instanceof FullyQualified && ! $this->reflectionProvider->hasClass(
$classLike->extends->toString()
)) {
return null;
}

$scope = $node->getAttribute(AttributeKey::SCOPE);

$parentClassReflection = $this->parentClassScopeResolver->resolveParentClassReflection($scope);
Expand Down

0 comments on commit 4bac761

Please sign in to comment.