Browse Source

PhpdocToCommentFixer - allow multiple "(" pairs.

SpacePossum 7 years ago
parent
commit
74f7dfc04b

+ 7 - 3
src/Fixer/Phpdoc/PhpdocToCommentFixer.php

@@ -92,15 +92,19 @@ foreach($connections as $key => $sqlite) {
                 continue;
             }
 
-            $nextIndex = $tokens->getNextMeaningfulToken($index);
-            $nextToken = null !== $nextIndex ? $tokens[$nextIndex] : null;
+            $nextIndex = $index;
+            do {
+                $nextIndex = $tokens->getNextMeaningfulToken($nextIndex);
+            } while (null !== $nextIndex && $tokens[$nextIndex]->equals('('));
 
-            if (null === $nextToken || $nextToken->equals('}')) {
+            if (null === $nextIndex || $tokens[$nextIndex]->equals('}')) {
                 $tokens[$index] = new Token(array(T_COMMENT, '/*'.ltrim($token->getContent(), '/*')));
 
                 continue;
             }
 
+            $nextToken = $tokens[$nextIndex];
+
             if ($this->isStructuralElement($nextToken)) {
                 continue;
             }

+ 49 - 0
tests/Fixer/Phpdoc/PhpdocToCommentFixerTest.php

@@ -534,6 +534,25 @@ class A
 ',
         );
 
+        $cases[] = array('<?php
+/** header */
+echo 123;
+
+/** @var int $bar1 */
+(print($bar1 = 0));
+            ',
+        );
+
+        $cases[] = array(
+            '<?php
+/** header */
+echo 123;
+
+/** @var ClassLoader $loader */
+$loader = require __DIR__.\'/../vendor/autoload.php\';
+',
+        );
+
         return $cases;
     }
 
@@ -555,6 +574,36 @@ trait DocBlocks
         );
     }
 
+    /**
+     * @param string      $expected
+     * @param null|string $input
+     *
+     * @dataProvider provideFix70Cases
+     * @requires PHP 7.0
+     */
+    public function testFix70($expected, $input = null)
+    {
+        $this->doTest($expected, $input);
+    }
+
+    public function provideFix70Cases()
+    {
+        return array(
+            array(
+                '<?php
+/** header */
+echo 123;
+
+/** @var User $bar3 */
+($bar3 = tmp())->doSomething();
+
+/** @var Session $session */ # test
+$session = new Session();
+                ',
+            ),
+        );
+    }
+
     /**
      * @param string      $expected
      * @param null|string $input