Browse Source

minor: PhpdocAlignFixer - support cases with type and variable separated with no space (#6921)

Kuba Werłos 1 year ago
parent
commit
546516ad40
2 changed files with 32 additions and 2 deletions
  1. 1 1
      src/Fixer/Phpdoc/PhpdocAlignFixer.php
  2. 31 1
      tests/Fixer/Phpdoc/PhpdocAlignFixerTest.php

+ 1 - 1
src/Fixer/Phpdoc/PhpdocAlignFixer.php

@@ -119,7 +119,7 @@ final class PhpdocAlignFixer extends AbstractFixer implements ConfigurableFixerI
 
         // e.g. @param <hint> <$var>
         if ([] !== $tagsWithNameToAlign) {
-            $types[] = '(?P<tag>'.implode('|', $tagsWithNameToAlign).')\s+(?P<hint>(?:'.TypeExpression::REGEX_TYPES.')?)\s+(?P<var>(?:&|\.{3})?\$\S+)';
+            $types[] = '(?P<tag>'.implode('|', $tagsWithNameToAlign).')\s+(?P<hint>(?:'.TypeExpression::REGEX_TYPES.')?)\s*(?P<var>(?:&|\.{3})?\$\S+)';
         }
 
         // e.g. @return <hint>

+ 31 - 1
tests/Fixer/Phpdoc/PhpdocAlignFixerTest.php

@@ -25,7 +25,37 @@ use PhpCsFixer\WhitespacesFixerConfig;
  */
 final class PhpdocAlignFixerTest extends AbstractFixerTestCase
 {
-    public function testFix(): void
+    /**
+     * @dataProvider provideFixCases
+     *
+     * @param array{align: string, tags: array<string>} $configuration
+     */
+    public function testFix(array $configuration, string $expected, ?string $input = null): void
+    {
+        $this->fixer->configure($configuration);
+        $this->doTest($expected, $input);
+    }
+
+    public static function provideFixCases(): iterable
+    {
+        yield [
+            ['tags' => ['param']],
+            '<?php
+                    /**
+                     * @param int $a
+                     * @param int $b
+                     * @param int $c
+                     */',
+            '<?php
+                    /**
+                     * @param int    $a
+                     * @param int $b
+                     * @param int$c
+                     */',
+        ];
+    }
+
+    public function testFixAligningParams(): void
     {
         $this->fixer->configure(['tags' => ['param']]);