Skip to content

Commit 4011bde

Browse files
committed
Fix Printer
1 parent b5e21fa commit 4011bde

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/Printer/Printer.php

+19-19
Original file line numberDiff line numberDiff line change
@@ -550,26 +550,26 @@ private function printArrayFormatPreserving(array $nodes, array $originalNodes,
550550

551551
foreach ($diff as $i => $diffElem) {
552552
$diffType = $diffElem->type;
553-
$arrItem = $diffElem->new;
554-
$origArrayItem = $diffElem->old;
553+
$newNode = $diffElem->new;
554+
$originalNode = $diffElem->old;
555555
if ($diffType === DiffElem::TYPE_KEEP || $diffType === DiffElem::TYPE_REPLACE) {
556556
$beforeFirstKeepOrReplace = false;
557-
if (!$arrItem instanceof Node || !$origArrayItem instanceof Node) {
557+
if (!$newNode instanceof Node || !$originalNode instanceof Node) {
558558
return null;
559559
}
560560

561561
/** @var int $itemStartPos */
562-
$itemStartPos = $origArrayItem->getAttribute(Attribute::START_INDEX);
562+
$itemStartPos = $originalNode->getAttribute(Attribute::START_INDEX);
563563

564564
/** @var int $itemEndPos */
565-
$itemEndPos = $origArrayItem->getAttribute(Attribute::END_INDEX);
565+
$itemEndPos = $originalNode->getAttribute(Attribute::END_INDEX);
566566

567567
if ($itemStartPos < 0 || $itemEndPos < 0 || $itemStartPos < $tokenIndex) {
568568
throw new LogicException();
569569
}
570570

571-
$comments = $arrItem->getAttribute(Attribute::COMMENTS) ?? [];
572-
$origComments = $origArrayItem->getAttribute(Attribute::COMMENTS) ?? [];
571+
$comments = $newNode->getAttribute(Attribute::COMMENTS) ?? [];
572+
$origComments = $originalNode->getAttribute(Attribute::COMMENTS) ?? [];
573573

574574
$commentStartPos = count($origComments) > 0 ? $origComments[0]->startIndex : $itemStartPos;
575575
assert($commentStartPos >= 0);
@@ -608,8 +608,8 @@ private function printArrayFormatPreserving(array $nodes, array $originalNodes,
608608
}
609609

610610
$parenthesesNeeded = isset($this->parenthesesListMap[$mapKey])
611-
&& in_array(get_class($arrItem), $this->parenthesesListMap[$mapKey], true)
612-
&& !in_array(get_class($origArrayItem), $this->parenthesesListMap[$mapKey], true);
611+
&& in_array(get_class($newNode), $this->parenthesesListMap[$mapKey], true)
612+
&& !in_array(get_class($originalNode), $this->parenthesesListMap[$mapKey], true);
613613
$addParentheses = $parenthesesNeeded && !$originalTokens->hasParentheses($itemStartPos, $itemEndPos);
614614
if ($addParentheses) {
615615
$result .= '(';
@@ -622,7 +622,7 @@ private function printArrayFormatPreserving(array $nodes, array $originalNodes,
622622
}
623623
}
624624

625-
$result .= $this->printNodeFormatPreserving($arrItem, $originalTokens);
625+
$result .= $this->printNodeFormatPreserving($newNode, $originalTokens);
626626
if ($addParentheses) {
627627
$result .= ')';
628628
}
@@ -632,25 +632,25 @@ private function printArrayFormatPreserving(array $nodes, array $originalNodes,
632632
if ($insertStr === null) {
633633
return null;
634634
}
635-
if (!$arrItem instanceof Node) {
635+
if (!$newNode instanceof Node) {
636636
return null;
637637
}
638638

639-
if ($insertStr === ', ' && $isMultiline || count($arrItem->getAttribute(Attribute::COMMENTS) ?? []) > 0) {
639+
if ($insertStr === ', ' && $isMultiline || count($newNode->getAttribute(Attribute::COMMENTS) ?? []) > 0) {
640640
$insertStr = ',';
641641
$insertNewline = true;
642642
}
643643

644644
if ($beforeFirstKeepOrReplace) {
645645
// Will be inserted at the next "replace" or "keep" element
646-
$delayedAdd[] = $arrItem;
646+
$delayedAdd[] = $newNode;
647647
continue;
648648
}
649649

650650
/** @var int $itemEndPos */
651651
$itemEndPos = $tokenIndex - 1;
652652
if ($insertNewline) {
653-
$comments = $arrItem->getAttribute(Attribute::COMMENTS) ?? [];
653+
$comments = $newNode->getAttribute(Attribute::COMMENTS) ?? [];
654654
$result .= $insertStr;
655655
if (count($comments) > 0) {
656656
$result .= sprintf('%s%s*%s', $originalTokens->getDetectedNewline() ?? "\n", $beforeAsteriskIndent, $afterAsteriskIndent);
@@ -662,28 +662,28 @@ private function printArrayFormatPreserving(array $nodes, array $originalNodes,
662662
}
663663

664664
$parenthesesNeeded = isset($this->parenthesesListMap[$mapKey])
665-
&& in_array(get_class($arrItem), $this->parenthesesListMap[$mapKey], true);
665+
&& in_array(get_class($newNode), $this->parenthesesListMap[$mapKey], true);
666666
if ($parenthesesNeeded) {
667667
$result .= '(';
668668
}
669669

670-
$result .= $this->printNodeFormatPreserving($arrItem, $originalTokens);
670+
$result .= $this->printNodeFormatPreserving($newNode, $originalTokens);
671671
if ($parenthesesNeeded) {
672672
$result .= ')';
673673
}
674674

675675
$tokenIndex = $itemEndPos + 1;
676676

677677
} elseif ($diffType === DiffElem::TYPE_REMOVE) {
678-
if (!$origArrayItem instanceof Node) {
678+
if (!$originalNode instanceof Node) {
679679
return null;
680680
}
681681

682682
/** @var int $itemStartPos */
683-
$itemStartPos = $origArrayItem->getAttribute(Attribute::START_INDEX);
683+
$itemStartPos = $originalNode->getAttribute(Attribute::START_INDEX);
684684

685685
/** @var int $itemEndPos */
686-
$itemEndPos = $origArrayItem->getAttribute(Attribute::END_INDEX);
686+
$itemEndPos = $originalNode->getAttribute(Attribute::END_INDEX);
687687
if ($itemStartPos < 0 || $itemEndPos < 0) {
688688
throw new LogicException();
689689
}

0 commit comments

Comments
 (0)