|
60 | 60 | use PHPStan\PhpDocParser\Parser\TokenIterator; |
61 | 61 | use function array_keys; |
62 | 62 | use function array_map; |
| 63 | +use function assert; |
63 | 64 | use function count; |
64 | 65 | use function get_class; |
65 | 66 | use function get_object_vars; |
|
68 | 69 | use function is_array; |
69 | 70 | use function preg_match_all; |
70 | 71 | use function sprintf; |
| 72 | +use function str_replace; |
71 | 73 | use function strlen; |
72 | 74 | use function strpos; |
73 | 75 | use function trim; |
@@ -538,12 +540,8 @@ private function printArrayFormatPreserving(array $nodes, array $originalNodes, |
538 | 540 | $comments = $arrItem->getAttribute(Attribute::COMMENTS) ?? []; |
539 | 541 | $origComments = $origArrayItem->getAttribute(Attribute::COMMENTS) ?? []; |
540 | 542 |
|
541 | | - if(count($comments) && !count($origComments)) { |
542 | | - $idfdf= 5; |
543 | | - } |
544 | | - |
545 | | - $commentStartPos = count($origComments) ? $origComments[0]->startIndex : $itemStartPos; |
546 | | - \assert($commentStartPos >= 0); |
| 543 | + $commentStartPos = count($origComments) > 0 ? $origComments[0]->startIndex : $itemStartPos; |
| 544 | + assert($commentStartPos >= 0); |
547 | 545 |
|
548 | 546 | $result .= $originalTokens->getContentBetween($tokenIndex, $itemStartPos); |
549 | 547 |
|
@@ -578,7 +576,7 @@ private function printArrayFormatPreserving(array $nodes, array $originalNodes, |
578 | 576 | } |
579 | 577 |
|
580 | 578 | if ($comments !== $origComments) { |
581 | | - if ($comments) { |
| 579 | + if (count($comments) > 0) { |
582 | 580 | $result .= $this->pComments($comments, $beforeAsteriskIndent, $afterAsteriskIndent);// . "\n"; |
583 | 581 | $result .= sprintf('%s%s*%s', $originalTokens->getDetectedNewline() ?? "\n", $beforeAsteriskIndent, $afterAsteriskIndent); |
584 | 582 | } |
@@ -707,7 +705,7 @@ protected function pComments(array $comments, string $beforeAsteriskIndent, stri |
707 | 705 | $formattedComments = []; |
708 | 706 |
|
709 | 707 | foreach ($comments as $comment) { |
710 | | - $formattedComments[] = str_replace("\n", "\n".$beforeAsteriskIndent."*".$afterAsteriskIndent, $comment->getReformattedText() ?? ''); |
| 708 | + $formattedComments[] = str_replace("\n", "\n" . $beforeAsteriskIndent . '*' . $afterAsteriskIndent, $comment->getReformattedText() ?? ''); |
711 | 709 | } |
712 | 710 |
|
713 | 711 | return implode("\n", $formattedComments); |
|
0 commit comments