Browse Source

PhpdocTypesFixer - fix recognizing callable

Kuba Werłos 3 years ago
parent
commit
c8501a33cf

+ 1 - 1
src/DocBlock/Annotation.php

@@ -285,7 +285,7 @@ final class Annotation
             }
 
             $matchingResult = Preg::match(
-                '{^(?:\s*\*|/\*\*)\s*@'.$name.'\s+'.TypeExpression::REGEX_TYPES.'(?:(?:[*\h\v]|\&[\.\$]).*)?\r?$}sx',
+                '{^(?:\s*\*|/\*\*)\s*@'.$name.'\s+'.TypeExpression::REGEX_TYPES.'(?:(?:[*\h\v]|\&[\.\$]).*)?\r?$}isx',
                 $this->lines[0]->getContent(),
                 $matches
             );

+ 4 - 0
tests/DocBlock/AnnotationTest.php

@@ -437,6 +437,10 @@ final class AnnotationTest extends TestCase
                 ['Closure(string)'],
                 '/** @param Closure(string) $function',
             ],
+            [
+                ['closure()'],
+                '/** @param closure() $function',
+            ],
             [
                 ['array  <  int   , callable  (  string  )  :   bool  >'],
                 '/** @param   array  <  int   , callable  (  string  )  :   bool  > $function',

+ 22 - 0
tests/Fixer/Phpdoc/PhpdocTypesFixerTest.php

@@ -28,6 +28,14 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  */
 final class PhpdocTypesFixerTest extends AbstractFixerTestCase
 {
+    /**
+     * @dataProvider provideFixCases
+     */
+    public function testFix(string $expected, ?string $input = null): void
+    {
+        $this->doTest($expected, $input);
+    }
+
     public function testWindowsLinebreaks(): void
     {
         $this->doTest(
@@ -284,6 +292,20 @@ EOF;
         );
     }
 
+    public static function provideFixCases(): iterable
+    {
+        yield 'callable' => [
+            '<?php /**
+                    * @param callable(): void $b
+                    * @param callable(bool, int, string): float $c
+                    */',
+            '<?php /**
+                    * @param Callable(): VOID $b
+                    * @param CALLABLE(BOOL, INT, STRING): FLOAT $c
+                    */',
+        ];
+    }
+
     public function testWrongConfig(): void
     {
         $this->expectException(InvalidFixerConfigurationException::class);