Browse Source

minor: PhpdocToCommentFixer - allow phpdoc comments before trait use statement. Fixes #6092 (#6565)

Joyce Babu 2 years ago
parent
commit
2cbb591bb6

+ 4 - 0
src/Tokenizer/Analyzer/CommentsAnalyzer.php

@@ -106,6 +106,10 @@ final class CommentsAnalyzer
             return true;
         }
 
+        if ($tokens[$nextIndex]->isGivenKind(CT::T_USE_TRAIT)) {
+            return true;
+        }
+
         return false;
     }
 

+ 4 - 0
tests/Fixer/Comment/CommentToPhpdocFixerTest.php

@@ -334,6 +334,10 @@ EOT
                 namespace Foo\Bar;
 ',
             ],
+            [
+                '<?php /* header comment */ $foo = true; class Foo { /** @phpstan-use Bar<Baz> $bar */ use Bar; }',
+                '<?php /* header comment */ $foo = true; class Foo { /* @phpstan-use Bar<Baz> $bar */ use Bar; }',
+            ],
         ];
     }
 }

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

@@ -55,6 +55,11 @@ final class PhpdocToCommentFixerTest extends AbstractFixerTestCase
  */
 class DocBlocks
 {
+    /**
+     * Do not convert this
+     */
+    use TestTrait;
+
     /**
      * Do not convert this
      */

+ 1 - 0
tests/Tokenizer/Analyzer/CommentsAnalyzerTest.php

@@ -238,6 +238,7 @@ $bar;',
             ['<?php class Foo { /* Before property */ public $bar; }'],
             ['<?php class Foo { /* Before property */ var $bar; }'],
             ['<?php class Foo { /* Before function */ function bar() {} }'],
+            ['<?php class Foo { /* Before use */ use Bar; }'],
             ['<?php class Foo { /* Before function */ final function bar() {} }'],
             ['<?php class Foo { /* Before function */ private function bar() {} }'],
             ['<?php class Foo { /* Before function */ protected function bar() {} }'],