mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-10 10:40:53 +01:00
f9fdebfe58
[DowngradePhp74] Handle nested uses on ArrowFunctionToAnonymousFunctionRector (#1040)
60 lines
3.1 KiB
PHP
60 lines
3.1 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 RectorPrefix20211023\Symplify\SimplePhpDocParser\PhpDocNodeTraverser;
|
|
use RectorPrefix20211023\Symplify\SimplePhpDocParser\PhpDocNodeVisitor\CloningPhpDocNodeVisitor;
|
|
use RectorPrefix20211023\Symplify\SimplePhpDocParser\PhpDocNodeVisitor\ParentConnectingPhpDocNodeVisitor;
|
|
/**
|
|
* @see \Rector\Tests\BetterPhpDocParser\PhpDocNodeMapperTest
|
|
*/
|
|
final class PhpDocNodeMapper
|
|
{
|
|
/**
|
|
* @var \Rector\BetterPhpDocParser\DataProvider\CurrentTokenIteratorProvider
|
|
*/
|
|
private $currentTokenIteratorProvider;
|
|
/**
|
|
* @var \Symplify\SimplePhpDocParser\PhpDocNodeVisitor\ParentConnectingPhpDocNodeVisitor
|
|
*/
|
|
private $parentConnectingPhpDocNodeVisitor;
|
|
/**
|
|
* @var \Symplify\SimplePhpDocParser\PhpDocNodeVisitor\CloningPhpDocNodeVisitor
|
|
*/
|
|
private $cloningPhpDocNodeVisitor;
|
|
/**
|
|
* @var \Rector\BetterPhpDocParser\Contract\BasePhpDocNodeVisitorInterface[]
|
|
*/
|
|
private $phpDocNodeVisitors;
|
|
/**
|
|
* @param BasePhpDocNodeVisitorInterface[] $phpDocNodeVisitors
|
|
*/
|
|
public function __construct(\Rector\BetterPhpDocParser\DataProvider\CurrentTokenIteratorProvider $currentTokenIteratorProvider, \RectorPrefix20211023\Symplify\SimplePhpDocParser\PhpDocNodeVisitor\ParentConnectingPhpDocNodeVisitor $parentConnectingPhpDocNodeVisitor, \RectorPrefix20211023\Symplify\SimplePhpDocParser\PhpDocNodeVisitor\CloningPhpDocNodeVisitor $cloningPhpDocNodeVisitor, array $phpDocNodeVisitors)
|
|
{
|
|
$this->currentTokenIteratorProvider = $currentTokenIteratorProvider;
|
|
$this->parentConnectingPhpDocNodeVisitor = $parentConnectingPhpDocNodeVisitor;
|
|
$this->cloningPhpDocNodeVisitor = $cloningPhpDocNodeVisitor;
|
|
$this->phpDocNodeVisitors = $phpDocNodeVisitors;
|
|
}
|
|
public function transform(\PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode $phpDocNode, \Rector\BetterPhpDocParser\ValueObject\Parser\BetterTokenIterator $betterTokenIterator) : void
|
|
{
|
|
$this->currentTokenIteratorProvider->setBetterTokenIterator($betterTokenIterator);
|
|
$parentPhpDocNodeTraverser = new \RectorPrefix20211023\Symplify\SimplePhpDocParser\PhpDocNodeTraverser();
|
|
$parentPhpDocNodeTraverser->addPhpDocNodeVisitor($this->parentConnectingPhpDocNodeVisitor);
|
|
$parentPhpDocNodeTraverser->traverse($phpDocNode);
|
|
$cloningPhpDocNodeTraverser = new \RectorPrefix20211023\Symplify\SimplePhpDocParser\PhpDocNodeTraverser();
|
|
$cloningPhpDocNodeTraverser->addPhpDocNodeVisitor($this->cloningPhpDocNodeVisitor);
|
|
$cloningPhpDocNodeTraverser->traverse($phpDocNode);
|
|
$phpDocNodeTraverser = new \RectorPrefix20211023\Symplify\SimplePhpDocParser\PhpDocNodeTraverser();
|
|
foreach ($this->phpDocNodeVisitors as $phpDocNodeVisitor) {
|
|
$phpDocNodeTraverser->addPhpDocNodeVisitor($phpDocNodeVisitor);
|
|
}
|
|
$phpDocNodeTraverser->traverse($phpDocNode);
|
|
}
|
|
}
|