Skip to content

Commit

Permalink
handle multiple comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shmax committed Sep 28, 2023
1 parent 9bea470 commit 5d9be65
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Printer/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ protected function pComments(array $comments, string $beforeAsteriskIndent, stri
$formattedComments[] = str_replace("\n", "\n" . $beforeAsteriskIndent . '*' . $afterAsteriskIndent, $comment->getReformattedText() ?? '');
}

return implode("\n", $formattedComments);
return implode("\n$beforeAsteriskIndent*$afterAsteriskIndent", $formattedComments);
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/PHPStan/Parser/TypeParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,19 @@ public function provideParseData(): array
),
]),
],
[
'array{
/* a is for apple */ /* and also for aardvark */
a: int,
}',
new ArrayShapeNode([
new ArrayShapeItemNode(
new IdentifierTypeNode('a'),
false,
new IdentifierTypeNode('int')
),
]),
],
[
'array{
// a is for apple
Expand Down
16 changes: 15 additions & 1 deletion tests/PHPStan/Printer/PrinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,17 @@ public function enterNode(Node $node)
*/'
)]);
$node->items[] = $commentedNode;

$commentedNode = new ArrayShapeItemNode(new IdentifierTypeNode('f'), false, new IdentifierTypeNode('string'));
$commentedNode->setAttribute(Attribute::COMMENTS, [
new Comment(
'/* A single line comment */'
),
new Comment(
'/* Another one on the same line */'
)
]);
$node->items[] = $commentedNode;
}

return $node;
Expand Down Expand Up @@ -722,7 +733,10 @@ public function enterNode(Node $node)
* * multiline
* * comment with leading asterisks
* */
* e: string
* e: string,
* /* A single line comment */
* /* Another one on the same line */
* f: string
* }
*/',
$addItemsWithCommentsToMultilineArrayShape,
Expand Down

0 comments on commit 5d9be65

Please sign in to comment.