Browse Source

feat: PhpdocSummaryFixer - support lists in description (#7385)

Dariusz Rumiński 1 year ago
parent
commit
3a60ff10b9

+ 7 - 2
src/Fixer/Phpdoc/PhpdocSummaryFixer.php

@@ -72,7 +72,12 @@ function foo () {}
                 $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()]);
                 }
@@ -89,6 +94,6 @@ function foo () {}
             return true;
         }
 
-        return $content !== rtrim($content, '.。!?¡¿!?');
+        return $content !== rtrim($content, '.:。!?¡¿!?');
     }
 }

+ 23 - 0
tests/Fixer/Phpdoc/PhpdocSummaryFixerTest.php

@@ -203,6 +203,29 @@ final class PhpdocSummaryFixerTest extends AbstractFixerTestCase
         $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'