@@ -550,26 +550,26 @@ private function printArrayFormatPreserving(array $nodes, array $originalNodes,
550
550
551
551
foreach ($ diff as $ i => $ diffElem ) {
552
552
$ diffType = $ diffElem ->type ;
553
- $ arrItem = $ diffElem ->new ;
554
- $ origArrayItem = $ diffElem ->old ;
553
+ $ newNode = $ diffElem ->new ;
554
+ $ originalNode = $ diffElem ->old ;
555
555
if ($ diffType === DiffElem::TYPE_KEEP || $ diffType === DiffElem::TYPE_REPLACE ) {
556
556
$ beforeFirstKeepOrReplace = false ;
557
- if (!$ arrItem instanceof Node || !$ origArrayItem instanceof Node) {
557
+ if (!$ newNode instanceof Node || !$ originalNode instanceof Node) {
558
558
return null ;
559
559
}
560
560
561
561
/** @var int $itemStartPos */
562
- $ itemStartPos = $ origArrayItem ->getAttribute (Attribute::START_INDEX );
562
+ $ itemStartPos = $ originalNode ->getAttribute (Attribute::START_INDEX );
563
563
564
564
/** @var int $itemEndPos */
565
- $ itemEndPos = $ origArrayItem ->getAttribute (Attribute::END_INDEX );
565
+ $ itemEndPos = $ originalNode ->getAttribute (Attribute::END_INDEX );
566
566
567
567
if ($ itemStartPos < 0 || $ itemEndPos < 0 || $ itemStartPos < $ tokenIndex ) {
568
568
throw new LogicException ();
569
569
}
570
570
571
- $ comments = $ arrItem ->getAttribute (Attribute::COMMENTS ) ?? [];
572
- $ origComments = $ origArrayItem ->getAttribute (Attribute::COMMENTS ) ?? [];
571
+ $ comments = $ newNode ->getAttribute (Attribute::COMMENTS ) ?? [];
572
+ $ origComments = $ originalNode ->getAttribute (Attribute::COMMENTS ) ?? [];
573
573
574
574
$ commentStartPos = count ($ origComments ) > 0 ? $ origComments [0 ]->startIndex : $ itemStartPos ;
575
575
assert ($ commentStartPos >= 0 );
@@ -608,8 +608,8 @@ private function printArrayFormatPreserving(array $nodes, array $originalNodes,
608
608
}
609
609
610
610
$ 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 );
613
613
$ addParentheses = $ parenthesesNeeded && !$ originalTokens ->hasParentheses ($ itemStartPos , $ itemEndPos );
614
614
if ($ addParentheses ) {
615
615
$ result .= '( ' ;
@@ -622,7 +622,7 @@ private function printArrayFormatPreserving(array $nodes, array $originalNodes,
622
622
}
623
623
}
624
624
625
- $ result .= $ this ->printNodeFormatPreserving ($ arrItem , $ originalTokens );
625
+ $ result .= $ this ->printNodeFormatPreserving ($ newNode , $ originalTokens );
626
626
if ($ addParentheses ) {
627
627
$ result .= ') ' ;
628
628
}
@@ -632,25 +632,25 @@ private function printArrayFormatPreserving(array $nodes, array $originalNodes,
632
632
if ($ insertStr === null ) {
633
633
return null ;
634
634
}
635
- if (!$ arrItem instanceof Node) {
635
+ if (!$ newNode instanceof Node) {
636
636
return null ;
637
637
}
638
638
639
- if ($ insertStr === ', ' && $ isMultiline || count ($ arrItem ->getAttribute (Attribute::COMMENTS ) ?? []) > 0 ) {
639
+ if ($ insertStr === ', ' && $ isMultiline || count ($ newNode ->getAttribute (Attribute::COMMENTS ) ?? []) > 0 ) {
640
640
$ insertStr = ', ' ;
641
641
$ insertNewline = true ;
642
642
}
643
643
644
644
if ($ beforeFirstKeepOrReplace ) {
645
645
// Will be inserted at the next "replace" or "keep" element
646
- $ delayedAdd [] = $ arrItem ;
646
+ $ delayedAdd [] = $ newNode ;
647
647
continue ;
648
648
}
649
649
650
650
/** @var int $itemEndPos */
651
651
$ itemEndPos = $ tokenIndex - 1 ;
652
652
if ($ insertNewline ) {
653
- $ comments = $ arrItem ->getAttribute (Attribute::COMMENTS ) ?? [];
653
+ $ comments = $ newNode ->getAttribute (Attribute::COMMENTS ) ?? [];
654
654
$ result .= $ insertStr ;
655
655
if (count ($ comments ) > 0 ) {
656
656
$ result .= sprintf ('%s%s*%s ' , $ originalTokens ->getDetectedNewline () ?? "\n" , $ beforeAsteriskIndent , $ afterAsteriskIndent );
@@ -662,28 +662,28 @@ private function printArrayFormatPreserving(array $nodes, array $originalNodes,
662
662
}
663
663
664
664
$ 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 );
666
666
if ($ parenthesesNeeded ) {
667
667
$ result .= '( ' ;
668
668
}
669
669
670
- $ result .= $ this ->printNodeFormatPreserving ($ arrItem , $ originalTokens );
670
+ $ result .= $ this ->printNodeFormatPreserving ($ newNode , $ originalTokens );
671
671
if ($ parenthesesNeeded ) {
672
672
$ result .= ') ' ;
673
673
}
674
674
675
675
$ tokenIndex = $ itemEndPos + 1 ;
676
676
677
677
} elseif ($ diffType === DiffElem::TYPE_REMOVE ) {
678
- if (!$ origArrayItem instanceof Node) {
678
+ if (!$ originalNode instanceof Node) {
679
679
return null ;
680
680
}
681
681
682
682
/** @var int $itemStartPos */
683
- $ itemStartPos = $ origArrayItem ->getAttribute (Attribute::START_INDEX );
683
+ $ itemStartPos = $ originalNode ->getAttribute (Attribute::START_INDEX );
684
684
685
685
/** @var int $itemEndPos */
686
- $ itemEndPos = $ origArrayItem ->getAttribute (Attribute::END_INDEX );
686
+ $ itemEndPos = $ originalNode ->getAttribute (Attribute::END_INDEX );
687
687
if ($ itemStartPos < 0 || $ itemEndPos < 0 ) {
688
688
throw new LogicException ();
689
689
}
0 commit comments