Skip to content

Commit

Permalink
[Printer] Use <= 0 check for getStartTokenPos() for current node avai…
Browse files Browse the repository at this point in the history
…lability on MixPhpHtmlDecorator (#3308)

* [Printer] Use <= 0 check for getEndTokenPos() for current node availability on MixPhpHtmlDecorator

* start token pos

* [ci-review] Rector Rectify

* use return; instead of break; as no action after loop

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
samsonasik and actions-user committed Jan 26, 2023
1 parent 8ddb480 commit dda7cdb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 3 additions & 7 deletions src/NodeDecorator/MixPhpHtmlDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PhpParser\Node\Stmt\InlineHTML;
use PhpParser\Node\Stmt\Nop;
use Rector\Core\PhpParser\Comparing\NodeComparator;
use Rector\Core\ValueObject\Application\File;
use Rector\NodeRemoval\NodeRemover;
use Rector\NodeTypeResolver\Node\AttributeKey;

Expand All @@ -29,17 +28,14 @@ public function __construct(
/**
* @param Node[] $nodes
*/
public function decorateNextNodesInlineHTML(File $file, array $nodes): void
public function decorateNextNodesInlineHTML(array $nodes): void
{
$oldTokens = $file->getOldTokens();

foreach ($nodes as $key => $subNode) {
if ($subNode instanceof InlineHTML) {
continue;
}

$endTokenPost = $subNode->getEndTokenPos();
if (isset($oldTokens[$endTokenPost])) {
if ($subNode->getStartTokenPos() >= 0) {
return;
}

Expand All @@ -51,7 +47,7 @@ public function decorateNextNodesInlineHTML(File $file, array $nodes): void
if ($nodes[$key + 1] instanceof InlineHTML) {
// No token end? Just added
$nodes[$key + 1]->setAttribute(AttributeKey::ORIGINAL_NODE, null);
break;
return;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Rector/AbstractRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,9 @@ private function connectNodes(array $nodes, Node $node): void
}

if (count($nodes) > 1) {
$this->mixPhpHtmlDecorator->decorateNextNodesInlineHTML($this->file, $nodes);
$this->mixPhpHtmlDecorator->decorateNextNodesInlineHTML($nodes);
} elseif ($firstNode instanceof FileWithoutNamespace) {
$this->mixPhpHtmlDecorator->decorateNextNodesInlineHTML($this->file, $firstNode->stmts);
$this->mixPhpHtmlDecorator->decorateNextNodesInlineHTML($firstNode->stmts);
}

$nodeTraverser = new NodeTraverser();
Expand Down

0 comments on commit dda7cdb

Please sign in to comment.