Skip to content

Commit 5d9be65

Browse files
committed
handle multiple comments
1 parent 9bea470 commit 5d9be65

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/Printer/Printer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ protected function pComments(array $comments, string $beforeAsteriskIndent, stri
717717
$formattedComments[] = str_replace("\n", "\n" . $beforeAsteriskIndent . '*' . $afterAsteriskIndent, $comment->getReformattedText() ?? '');
718718
}
719719

720-
return implode("\n", $formattedComments);
720+
return implode("\n$beforeAsteriskIndent*$afterAsteriskIndent", $formattedComments);
721721
}
722722

723723
/**

tests/PHPStan/Parser/TypeParserTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,19 @@ public function provideParseData(): array
148148
),
149149
]),
150150
],
151+
[
152+
'array{
153+
/* a is for apple */ /* and also for aardvark */
154+
a: int,
155+
}',
156+
new ArrayShapeNode([
157+
new ArrayShapeItemNode(
158+
new IdentifierTypeNode('a'),
159+
false,
160+
new IdentifierTypeNode('int')
161+
),
162+
]),
163+
],
151164
[
152165
'array{
153166
// a is for apple

tests/PHPStan/Printer/PrinterTest.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,17 @@ public function enterNode(Node $node)
691691
*/'
692692
)]);
693693
$node->items[] = $commentedNode;
694+
695+
$commentedNode = new ArrayShapeItemNode(new IdentifierTypeNode('f'), false, new IdentifierTypeNode('string'));
696+
$commentedNode->setAttribute(Attribute::COMMENTS, [
697+
new Comment(
698+
'/* A single line comment */'
699+
),
700+
new Comment(
701+
'/* Another one on the same line */'
702+
)
703+
]);
704+
$node->items[] = $commentedNode;
694705
}
695706

696707
return $node;
@@ -722,7 +733,10 @@ public function enterNode(Node $node)
722733
* * multiline
723734
* * comment with leading asterisks
724735
* */
725-
* e: string
736+
* e: string,
737+
* /* A single line comment */
738+
* /* Another one on the same line */
739+
* f: string
726740
* }
727741
*/',
728742
$addItemsWithCommentsToMultilineArrayShape,

0 commit comments

Comments
 (0)