rector/rules/DeadCode/PhpDoc/DeadVarTagValueNodeAnalyzer.php

30 lines
946 B
PHP
Raw Normal View History

<?php
declare (strict_types=1);
2021-03-21 12:57:56 +00:00
namespace Rector\DeadCode\PhpDoc;
use PhpParser\Node\Stmt\Property;
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use Rector\NodeTypeResolver\TypeComparator\TypeComparator;
final class DeadVarTagValueNodeAnalyzer
{
/**
* @var TypeComparator
*/
private $typeComparator;
public function __construct(\Rector\NodeTypeResolver\TypeComparator\TypeComparator $typeComparator)
{
$this->typeComparator = $typeComparator;
}
public function isDead(\PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode $varTagValueNode, \PhpParser\Node\Stmt\Property $property) : bool
{
if ($property->type === null) {
return \false;
}
if (!$this->typeComparator->arePhpParserAndPhpStanPhpDocTypesEqual($property->type, $varTagValueNode->type, $property)) {
return \false;
}
return $varTagValueNode->description === '';
}
}