Skip to content

Commit

Permalink
feat: PhpdocSummaryFixer - support lists in description (#7385)
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed Oct 27, 2023
1 parent 282f8fe commit 3a60ff1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Fixer/Phpdoc/PhpdocSummaryFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
$line = $doc->getLine($end);
$content = rtrim($line->getContent());

if (!$this->isCorrectlyFormatted($content)) {
if (
// final line of Description is NOT properly formatted
!$this->isCorrectlyFormatted($content)
// and first line of Description, if different than final line, does NOT indicate a list
&& (1 === $end || ($doc->isMultiLine() && ':' !== substr(rtrim($doc->getLine(1)->getContent()), -1)))
) {
$line->setContent($content.'.'.$this->whitespacesConfig->getLineEnding());
$tokens[$index] = new Token([T_DOC_COMMENT, $doc->getContent()]);
}
Expand All @@ -89,6 +94,6 @@ private function isCorrectlyFormatted(string $content): bool
return true;
}

return $content !== rtrim($content, '.。!?¡¿!?');
return $content !== rtrim($content, '.:。!?¡¿!?');
}
}
23 changes: 23 additions & 0 deletions tests/Fixer/Phpdoc/PhpdocSummaryFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,29 @@ public function testFixMultiline(): void
$this->doTest($expected, $input);
}

public function testWithList(): void
{
$expected = <<<'EOF'
<?php
/**
* Options:
* * a: aaa
* * b: bbb
* * c: ccc
*/
/**
* Options:
*
* * a: aaa
* * b: bbb
* * c: ccc
*/
EOF;

$this->doTest($expected);
}

public function testWithTags(): void
{
$expected = <<<'EOF'
Expand Down

0 comments on commit 3a60ff1

Please sign in to comment.