Skip to content

Commit

Permalink
[BetterPhpDocParser] Clean up unnecessary create new ConstFetchNode()…
Browse files Browse the repository at this point in the history
… on ArrayItemClassNameDecorator (#5658)
  • Loading branch information
samsonasik committed Feb 22, 2024
1 parent b9ea5fd commit f5a45a5
Showing 1 changed file with 3 additions and 7 deletions.
Expand Up @@ -6,7 +6,6 @@

use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use PhpParser\Node as PhpNode;
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstFetchNode;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
use Rector\BetterPhpDocParser\Contract\PhpDocParser\PhpDocNodeDecoratorInterface;
Expand Down Expand Up @@ -49,19 +48,16 @@ public function decorate(PhpDocNode $phpDocNode, PhpNode $phpNode): void
return null;
}

$firstName = $splitScopeResolution[0];
$constFetchNode = new ConstFetchNode($firstName, $firstName);

$className = $this->resolveFullyQualifiedClass($constFetchNode, $phpNode);
$className = $this->resolveFullyQualifiedClass($splitScopeResolution[0], $phpNode);
$node->setAttribute(PhpDocAttributeKey::RESOLVED_CLASS, $className);

return $node;
});
}

private function resolveFullyQualifiedClass(ConstFetchNode $constFetchNode, PhpNode $phpNode): string
private function resolveFullyQualifiedClass(string $className, PhpNode $phpNode): string
{
$nameScope = $this->nameScopeFactory->createNameScopeFromNodeWithoutTemplateTypes($phpNode);
return $nameScope->resolveStringName($constFetchNode->className);
return $nameScope->resolveStringName($className);
}
}

0 comments on commit f5a45a5

Please sign in to comment.