2021-03-20 15:27:18 +00:00
|
|
|
<?php
|
|
|
|
|
2021-05-09 20:15:43 +00:00
|
|
|
declare (strict_types=1);
|
2022-06-06 17:12:56 +00:00
|
|
|
namespace Rector\BetterPhpDocParser;
|
2021-03-20 15:27:18 +00:00
|
|
|
|
2022-06-06 17:12:56 +00:00
|
|
|
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
|
|
|
|
use Rector\BetterPhpDocParser\Contract\BasePhpDocNodeVisitorInterface;
|
|
|
|
use Rector\BetterPhpDocParser\DataProvider\CurrentTokenIteratorProvider;
|
|
|
|
use Rector\BetterPhpDocParser\ValueObject\Parser\BetterTokenIterator;
|
2022-08-29 20:49:28 +00:00
|
|
|
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser;
|
|
|
|
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeVisitor\CloningPhpDocNodeVisitor;
|
|
|
|
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeVisitor\ParentConnectingPhpDocNodeVisitor;
|
2024-06-01 09:25:16 +00:00
|
|
|
use RectorPrefix202406\Webmozart\Assert\Assert;
|
2021-03-20 15:27:18 +00:00
|
|
|
/**
|
|
|
|
* @see \Rector\Tests\BetterPhpDocParser\PhpDocNodeMapperTest
|
|
|
|
*/
|
|
|
|
final class PhpDocNodeMapper
|
|
|
|
{
|
|
|
|
/**
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2021-05-10 23:39:21 +00:00
|
|
|
* @var \Rector\BetterPhpDocParser\DataProvider\CurrentTokenIteratorProvider
|
2021-04-04 09:01:11 +00:00
|
|
|
*/
|
2021-04-06 17:33:09 +00:00
|
|
|
private $currentTokenIteratorProvider;
|
2021-04-04 09:01:11 +00:00
|
|
|
/**
|
2023-09-13 19:21:21 +00:00
|
|
|
* @var BasePhpDocNodeVisitorInterface[]
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2021-04-04 09:01:11 +00:00
|
|
|
*/
|
2023-09-13 19:21:21 +00:00
|
|
|
private $phpDocNodeVisitors;
|
2021-04-06 17:33:09 +00:00
|
|
|
/**
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2023-09-13 19:21:21 +00:00
|
|
|
* @var \Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser
|
2021-04-06 17:33:09 +00:00
|
|
|
*/
|
2023-09-13 19:21:21 +00:00
|
|
|
private $phpDocNodeTraverser;
|
2021-04-06 17:33:09 +00:00
|
|
|
/**
|
|
|
|
* @param BasePhpDocNodeVisitorInterface[] $phpDocNodeVisitors
|
|
|
|
*/
|
2023-08-15 22:27:51 +00:00
|
|
|
public function __construct(CurrentTokenIteratorProvider $currentTokenIteratorProvider, ParentConnectingPhpDocNodeVisitor $parentConnectingPhpDocNodeVisitor, CloningPhpDocNodeVisitor $cloningPhpDocNodeVisitor, array $phpDocNodeVisitors)
|
2021-05-09 20:15:43 +00:00
|
|
|
{
|
2021-04-06 17:33:09 +00:00
|
|
|
$this->currentTokenIteratorProvider = $currentTokenIteratorProvider;
|
2021-05-10 23:39:21 +00:00
|
|
|
$this->phpDocNodeVisitors = $phpDocNodeVisitors;
|
2023-08-08 16:32:19 +00:00
|
|
|
Assert::notEmpty($phpDocNodeVisitors);
|
2023-09-13 19:21:21 +00:00
|
|
|
$this->phpDocNodeTraverser = new PhpDocNodeTraverser();
|
|
|
|
$this->phpDocNodeTraverser->addPhpDocNodeVisitor($parentConnectingPhpDocNodeVisitor);
|
|
|
|
$this->phpDocNodeTraverser->addPhpDocNodeVisitor($cloningPhpDocNodeVisitor);
|
|
|
|
foreach ($this->phpDocNodeVisitors as $phpDocNodeVisitor) {
|
|
|
|
$this->phpDocNodeTraverser->addPhpDocNodeVisitor($phpDocNodeVisitor);
|
|
|
|
}
|
2021-03-20 15:27:18 +00:00
|
|
|
}
|
2022-06-07 08:22:29 +00:00
|
|
|
public function transform(PhpDocNode $phpDocNode, BetterTokenIterator $betterTokenIterator) : void
|
2021-03-20 15:27:18 +00:00
|
|
|
{
|
2021-04-06 17:33:09 +00:00
|
|
|
$this->currentTokenIteratorProvider->setBetterTokenIterator($betterTokenIterator);
|
2023-09-13 19:21:21 +00:00
|
|
|
$this->phpDocNodeTraverser->traverse($phpDocNode);
|
2021-04-04 09:01:11 +00:00
|
|
|
}
|
2021-03-20 15:27:18 +00:00
|
|
|
}
|