mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-19 14:27:14 +01:00
5edd3689a8
bb59a7c99a
[DX] Inline symplify/astral to use only active classes (#2851)
64 lines
2.7 KiB
PHP
64 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\BetterPhpDocParser;
|
|
|
|
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
|
|
use Rector\BetterPhpDocParser\Contract\BasePhpDocNodeVisitorInterface;
|
|
use Rector\BetterPhpDocParser\DataProvider\CurrentTokenIteratorProvider;
|
|
use Rector\BetterPhpDocParser\ValueObject\Parser\BetterTokenIterator;
|
|
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser;
|
|
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeVisitor\CloningPhpDocNodeVisitor;
|
|
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeVisitor\ParentConnectingPhpDocNodeVisitor;
|
|
/**
|
|
* @see \Rector\Tests\BetterPhpDocParser\PhpDocNodeMapperTest
|
|
*/
|
|
final class PhpDocNodeMapper
|
|
{
|
|
/**
|
|
* @readonly
|
|
* @var \Rector\BetterPhpDocParser\DataProvider\CurrentTokenIteratorProvider
|
|
*/
|
|
private $currentTokenIteratorProvider;
|
|
/**
|
|
* @readonly
|
|
* @var \Rector\PhpDocParser\PhpDocParser\PhpDocNodeVisitor\ParentConnectingPhpDocNodeVisitor
|
|
*/
|
|
private $parentConnectingPhpDocNodeVisitor;
|
|
/**
|
|
* @readonly
|
|
* @var \Rector\PhpDocParser\PhpDocParser\PhpDocNodeVisitor\CloningPhpDocNodeVisitor
|
|
*/
|
|
private $cloningPhpDocNodeVisitor;
|
|
/**
|
|
* @var BasePhpDocNodeVisitorInterface[]
|
|
* @readonly
|
|
*/
|
|
private $phpDocNodeVisitors;
|
|
/**
|
|
* @param BasePhpDocNodeVisitorInterface[] $phpDocNodeVisitors
|
|
*/
|
|
public function __construct(CurrentTokenIteratorProvider $currentTokenIteratorProvider, ParentConnectingPhpDocNodeVisitor $parentConnectingPhpDocNodeVisitor, CloningPhpDocNodeVisitor $cloningPhpDocNodeVisitor, array $phpDocNodeVisitors)
|
|
{
|
|
$this->currentTokenIteratorProvider = $currentTokenIteratorProvider;
|
|
$this->parentConnectingPhpDocNodeVisitor = $parentConnectingPhpDocNodeVisitor;
|
|
$this->cloningPhpDocNodeVisitor = $cloningPhpDocNodeVisitor;
|
|
$this->phpDocNodeVisitors = $phpDocNodeVisitors;
|
|
}
|
|
public function transform(PhpDocNode $phpDocNode, BetterTokenIterator $betterTokenIterator) : void
|
|
{
|
|
$this->currentTokenIteratorProvider->setBetterTokenIterator($betterTokenIterator);
|
|
$parentPhpDocNodeTraverser = new PhpDocNodeTraverser();
|
|
$parentPhpDocNodeTraverser->addPhpDocNodeVisitor($this->parentConnectingPhpDocNodeVisitor);
|
|
$parentPhpDocNodeTraverser->traverse($phpDocNode);
|
|
$cloningPhpDocNodeTraverser = new PhpDocNodeTraverser();
|
|
$cloningPhpDocNodeTraverser->addPhpDocNodeVisitor($this->cloningPhpDocNodeVisitor);
|
|
$cloningPhpDocNodeTraverser->traverse($phpDocNode);
|
|
$phpDocNodeTraverser = new PhpDocNodeTraverser();
|
|
foreach ($this->phpDocNodeVisitors as $phpDocNodeVisitor) {
|
|
$phpDocNodeTraverser->addPhpDocNodeVisitor($phpDocNodeVisitor);
|
|
}
|
|
$phpDocNodeTraverser->traverse($phpDocNode);
|
|
}
|
|
}
|