Skip to content

Commit

Permalink
Helpers::formatDocComment() added option $forceMultiLine
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 4, 2022
1 parent 44a7a51 commit 22c9ed7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/PhpGenerator/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ public static function formatArgs(string $statement, array $args): string
}


public static function formatDocComment(string $content): string
public static function formatDocComment(string $content, bool $forceMultiLine = false): string
{
$s = trim($content);
$s = str_replace('*/', '* /', $s);
if ($s === '') {
return '';
} elseif (str_contains($content, "\n")) {
} elseif ($forceMultiLine || str_contains($content, "\n")) {
$s = str_replace("\n", "\n * ", "/**\n$s") . "\n */";
return Nette\Utils\Strings::normalize($s) . "\n";
} else {
Expand Down
1 change: 1 addition & 0 deletions tests/PhpGenerator/Helpers.comments.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require __DIR__ . '/../bootstrap.php';
Assert::same('', Helpers::formatDocComment(' '));
Assert::same("/** @var string */\n", Helpers::formatDocComment('@var string'));
Assert::same("/**\n * @var string\n */\n", Helpers::formatDocComment("@var string\n"));
Assert::same("/**\n * @var string\n */\n", Helpers::formatDocComment('@var string', true));
Assert::same("/**\n * A\n * B\n * C\n */\n", Helpers::formatDocComment("A\nB\nC\n"));
Assert::same("/**\n * @var string\n */\n", Helpers::formatDocComment("@var string \r\n"));
Assert::same("/**\n * A\n *\n * B\n */\n", Helpers::formatDocComment("A\n\nB"));
Expand Down

0 comments on commit 22c9ed7

Please sign in to comment.