Browse Source

Fix alignment of variadic params.

SpacePossum 8 years ago
parent
commit
a86ac531f1
2 changed files with 75 additions and 1 deletions
  1. 1 1
      src/Fixer/Phpdoc/PhpdocAlignFixer.php
  2. 74 0
      tests/Fixer/Phpdoc/PhpdocAlignFixerTest.php

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

@@ -35,7 +35,7 @@ final class PhpdocAlignFixer extends AbstractFixer implements WhitespacesAwareFi
 
         $indent = '(?P<indent>(?: {2}|\t)*)';
         // e.g. @param <hint> <$var>
-        $paramTag = '(?P<tag>param)\s+(?P<hint>[^$]+?)\s+(?P<var>&?\$[^\s]+)';
+        $paramTag = '(?P<tag>param)\s+(?P<hint>[^$]+?)\s+(?P<var>(?:&|\.{3})?\$[^\s]+)';
         // e.g. @return <hint>
         $otherTags = '(?P<tag2>return|throws|var|type)\s+(?P<hint2>[^\s]+?)';
         // optional <desc>

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

@@ -512,4 +512,78 @@ EOF;
 
         $this->doTest($expected, $input);
     }
+
+    /**
+     * @param string $expected
+     * @param string $input
+     *
+     * @requires PHP 5.6
+     * @dataProvider provideVariadicCases
+     */
+    public function testVariadicParams($expected, $input)
+    {
+        $this->doTest($expected, $input);
+    }
+
+    public function provideVariadicCases()
+    {
+        return array(
+            array(
+                '<?php
+final class Sample
+{
+    /**
+     * @param int[] $a    A
+     * @param int   &$b   B
+     * @param array ...$c C
+     */
+    public function sample2($a, &$b, ...$c)
+    {
+    }
+}
+',
+            '<?php
+final class Sample
+{
+    /**
+     * @param int[]       $a  A
+     * @param int          &$b B
+     * @param array ...$c    C
+     */
+    public function sample2($a, &$b, ...$c)
+    {
+    }
+}
+',
+            ),
+                        array(
+                '<?php
+final class Sample
+{
+    /**
+     * @param int     $a
+     * @param int     $b
+     * @param array[] ...$c
+     */
+    public function sample2($a, $b, ...$c)
+    {
+    }
+}
+',
+            '<?php
+final class Sample
+{
+    /**
+     * @param int       $a
+     * @param int    $b
+     * @param array[]      ...$c
+     */
+    public function sample2($a, $b, ...$c)
+    {
+    }
+}
+',
+            ),
+        );
+    }
 }