Skip to content

Commit

Permalink
[Performance][BetterPhpDocParser] Move create new PhpDocNodeTraverser…
Browse files Browse the repository at this point in the history
…() to __construct() on PhpDocNodeMapper (#5014)

* [Performance][BetterPhpDocParser] Move create new PhpDocNodeTraverser() in __construct() on PhpDocNodeMapper

* [ci-review] Rector Rectify

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user committed Sep 13, 2023
1 parent 74df774 commit 299d02c
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions packages/BetterPhpDocParser/PhpDocNodeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,31 @@
*/
final class PhpDocNodeMapper
{
private readonly PhpDocNodeTraverser $phpDocNodeTraverser;

/**
* @param BasePhpDocNodeVisitorInterface[] $phpDocNodeVisitors
*/
public function __construct(
private readonly CurrentTokenIteratorProvider $currentTokenIteratorProvider,
private readonly ParentConnectingPhpDocNodeVisitor $parentConnectingPhpDocNodeVisitor,
private readonly CloningPhpDocNodeVisitor $cloningPhpDocNodeVisitor,
ParentConnectingPhpDocNodeVisitor $parentConnectingPhpDocNodeVisitor,
CloningPhpDocNodeVisitor $cloningPhpDocNodeVisitor,
private readonly array $phpDocNodeVisitors
) {
Assert::notEmpty($phpDocNodeVisitors);
}

public function transform(PhpDocNode $phpDocNode, BetterTokenIterator $betterTokenIterator): void
{
$this->currentTokenIteratorProvider->setBetterTokenIterator($betterTokenIterator);

$phpDocNodeTraverser = new PhpDocNodeTraverser();
$phpDocNodeTraverser->addPhpDocNodeVisitor($this->parentConnectingPhpDocNodeVisitor);
$phpDocNodeTraverser->addPhpDocNodeVisitor($this->cloningPhpDocNodeVisitor);
$this->phpDocNodeTraverser = new PhpDocNodeTraverser();
$this->phpDocNodeTraverser->addPhpDocNodeVisitor($parentConnectingPhpDocNodeVisitor);
$this->phpDocNodeTraverser->addPhpDocNodeVisitor($cloningPhpDocNodeVisitor);

foreach ($this->phpDocNodeVisitors as $phpDocNodeVisitor) {
$phpDocNodeTraverser->addPhpDocNodeVisitor($phpDocNodeVisitor);
$this->phpDocNodeTraverser->addPhpDocNodeVisitor($phpDocNodeVisitor);
}
}

$phpDocNodeTraverser->traverse($phpDocNode);
public function transform(PhpDocNode $phpDocNode, BetterTokenIterator $betterTokenIterator): void
{
$this->currentTokenIteratorProvider->setBetterTokenIterator($betterTokenIterator);
$this->phpDocNodeTraverser->traverse($phpDocNode);
}
}

0 comments on commit 299d02c

Please sign in to comment.