Repository: FriendsOfPHP/PHP-CS-Fixer (php)

Issue:
"Use" annotation is converted to simple documentation
Hi !

## Bug report
   - PHP CS Fixer version: 3.2.1
   - Rule: phpdoc_to_comment 

"Use" annotation is converted to simple documentation by PHP CS Fixer.

### Code snippet that reproduces the problem


  ```php
  <?php
  class Test {
     /**
     * @use AutoDiscoveredValuesTrait<string>
     */
    use AutoDiscoveredValuesTrait;

  }
  ```

is tranformed into:


  ```php
  <?php
  class Test {
     /*
     * @use AutoDiscoveredValuesTrait<string>
     */
    use AutoDiscoveredValuesTrait;

  }


Pull request:
minor: PhpdocToCommentFixer - allow phpdoc comments before trait use statement. Fixes #6092
Related to #6092

PhpdocToCommentFixer currently removes phpdoc comments before `use SomeTrait;` statement in classes.

This phpstan uses phpdoc on `use SomeTrait;` for generics support.

Patch:
diff --git a/src/Tokenizer/Analyzer/CommentsAnalyzer.php b/src/Tokenizer/Analyzer/CommentsAnalyzer.php
index cfda768a9..0666a21da 100644
--- a/src/Tokenizer/Analyzer/CommentsAnalyzer.php
+++ b/src/Tokenizer/Analyzer/CommentsAnalyzer.php
@@ -106,6 +106,10 @@ public function isBeforeStructuralElement(Tokens $tokens, int $index): bool
             return true;
         }
 
+        if ($tokens[$nextIndex]->isGivenKind(CT::T_USE_TRAIT)) {
+            return true;
+        }
+
         return false;
     }
 


Test patch:
diff --git a/tests/Fixer/Comment/CommentToPhpdocFixerTest.php b/tests/Fixer/Comment/CommentToPhpdocFixerTest.php
index 6ad3eb190..ccd93f459 100644
--- a/tests/Fixer/Comment/CommentToPhpdocFixerTest.php
+++ b/tests/Fixer/Comment/CommentToPhpdocFixerTest.php
@@ -334,6 +334,10 @@ public function provideTestCases(): array
                 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; }',
+            ],
         ];
     }
 }
diff --git a/tests/Fixer/Phpdoc/PhpdocToCommentFixerTest.php b/tests/Fixer/Phpdoc/PhpdocToCommentFixerTest.php
index 34da69d77..4e22c5080 100644
--- a/tests/Fixer/Phpdoc/PhpdocToCommentFixerTest.php
+++ b/tests/Fixer/Phpdoc/PhpdocToCommentFixerTest.php
@@ -55,6 +55,11 @@ public function provideDocblocksCases(): array
  */
 class DocBlocks
 {
+    /**
+     * Do not convert this
+     */
+    use TestTrait;
+
     /**
      * Do not convert this
      */
diff --git a/tests/Tokenizer/Analyzer/CommentsAnalyzerTest.php b/tests/Tokenizer/Analyzer/CommentsAnalyzerTest.php
index 9e63e33a0..db5f96a18 100644
--- a/tests/Tokenizer/Analyzer/CommentsAnalyzerTest.php
+++ b/tests/Tokenizer/Analyzer/CommentsAnalyzerTest.php
@@ -238,6 +238,7 @@ public function providePhpdocCandidateCases(): array
             ['<?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() {} }'],