Skip to content

Commit

Permalink
[DeadCode] Remove parent lookup on DeadReturnTagValueNodeAnalyzer (#4235
Browse files Browse the repository at this point in the history
)
  • Loading branch information
samsonasik committed Jun 16, 2023
1 parent 53c6c5f commit 6488506
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions rules/DeadCode/PhpDoc/DeadReturnTagValueNodeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@
namespace Rector\DeadCode\PhpDoc;

use PhpParser\Node;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Trait_;
use PHPStan\Analyser\Scope;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\ThisTypeNode;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
use Rector\BetterPhpDocParser\ValueObject\Type\BracketsAwareUnionTypeNode;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\DeadCode\PhpDoc\Guard\StandaloneTypeRemovalGuard;
use Rector\DeadCode\TypeNodeAnalyzer\GenericTypeNodeAnalyzer;
use Rector\DeadCode\TypeNodeAnalyzer\MixedArrayTypeNodeAnalyzer;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\NodeTypeResolver\TypeComparator\TypeComparator;

final class DeadReturnTagValueNodeAnalyzer
{
public function __construct(
private readonly TypeComparator $typeComparator,
private readonly BetterNodeFinder $betterNodeFinder,
private readonly GenericTypeNodeAnalyzer $genericTypeNodeAnalyzer,
private readonly MixedArrayTypeNodeAnalyzer $mixedArrayTypeNodeAnalyzer,
private readonly StandaloneTypeRemovalGuard $standaloneTypeRemovalGuard,
Expand All @@ -38,8 +36,8 @@ public function isDead(ReturnTagValueNode $returnTagValueNode, ClassMethod $clas
return false;
}

$classLike = $this->betterNodeFinder->findParentType($classMethod, ClassLike::class);
if ($classLike instanceof Trait_ && $returnTagValueNode->type instanceof ThisTypeNode) {
$scope = $classMethod->getAttribute(AttributeKey::SCOPE);
if ($scope instanceof Scope && $scope->isInTrait() && $returnTagValueNode->type instanceof ThisTypeNode) {
return false;
}

Expand Down

0 comments on commit 6488506

Please sign in to comment.