Browse Source

fix: phpdoc_align - fix multiline tag alignment issue (#7630)

Dariusz Rumiński 1 year ago
parent
commit
cb5d2211f8
2 changed files with 21 additions and 4 deletions
  1. 5 4
      src/Fixer/Phpdoc/PhpdocAlignFixer.php
  2. 16 0
      tests/Fixer/Phpdoc/PhpdocAlignFixerTest.php

+ 5 - 4
src/Fixer/Phpdoc/PhpdocAlignFixer.php

@@ -258,7 +258,7 @@ final class PhpdocAlignFixer extends AbstractFixer implements ConfigurableFixerI
                 $varMax = max($varMax, \strlen($item['var']));
             }
 
-            $currTag = null;
+            $itemOpeningLine = null;
 
             // update
             foreach ($items as $j => $item) {
@@ -272,7 +272,7 @@ final class PhpdocAlignFixer extends AbstractFixer implements ConfigurableFixerI
 
                     $extraIndent = 2;
 
-                    if (\in_array($currTag, self::TAGS_WITH_NAME, true) || \in_array($currTag, self::TAGS_WITH_METHOD_SIGNATURE, true)) {
+                    if (\in_array($itemOpeningLine['tag'], self::TAGS_WITH_NAME, true) || \in_array($itemOpeningLine['tag'], self::TAGS_WITH_METHOD_SIGNATURE, true)) {
                         $extraIndent += $varMax + 1;
                     }
 
@@ -282,7 +282,8 @@ final class PhpdocAlignFixer extends AbstractFixer implements ConfigurableFixerI
 
                     $line =
                         $item['indent']
-                        .' *  '
+                        .' * '
+                        .('' !== $itemOpeningLine['hint'] ? ' ' : '')
                         .$this->getIndent(
                             $tagMax + $hintMax + $extraIndent,
                             $this->getLeftAlignedDescriptionIndent($items, $j)
@@ -294,7 +295,7 @@ final class PhpdocAlignFixer extends AbstractFixer implements ConfigurableFixerI
                     continue;
                 }
 
-                $currTag = $item['tag'];
+                $itemOpeningLine = $item;
 
                 $line =
                     $item['indent']

+ 16 - 0
tests/Fixer/Phpdoc/PhpdocAlignFixerTest.php

@@ -1323,5 +1323,21 @@ class Foo {}
  */
 ',
         ];
+
+        yield 'untyped param with multiline desc' => [
+            [],
+            '<?php
+/**
+ * @param $typeless Foo.
+ *                  Bar.
+ */
+function foo($typeless): void {}',
+            '<?php
+/**
+ * @param $typeless    Foo.
+ *                     Bar.
+ */
+function foo($typeless): void {}',
+        ];
     }
 }