rector/packages/BetterPhpDocParser/PhpDocNodeMapper.php
Abdul Malik Ikhsan fc10fce13d
[Rectify] [Php81] Enable Rectify on Readonly Property only (#1384)
* re-enable rectify and ecs

* [Rectify] [Php81] Enable Rectify on Readonly Property only

* comment

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

Co-authored-by: GitHub Action <action@github.com>
2021-12-04 15:32:52 +03:00

51 lines
2.0 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 Symplify\SimplePhpDocParser\PhpDocNodeTraverser;
use Symplify\SimplePhpDocParser\PhpDocNodeVisitor\CloningPhpDocNodeVisitor;
use Symplify\SimplePhpDocParser\PhpDocNodeVisitor\ParentConnectingPhpDocNodeVisitor;
/**
* @see \Rector\Tests\BetterPhpDocParser\PhpDocNodeMapperTest
*/
final class PhpDocNodeMapper
{
/**
* @param BasePhpDocNodeVisitorInterface[] $phpDocNodeVisitors
*/
public function __construct(
private readonly CurrentTokenIteratorProvider $currentTokenIteratorProvider,
private readonly ParentConnectingPhpDocNodeVisitor $parentConnectingPhpDocNodeVisitor,
private readonly CloningPhpDocNodeVisitor $cloningPhpDocNodeVisitor,
private readonly array $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);
}
}