Просмотр исходного кода

bug: PhpdocTypesFixer - handle types with no space between type and variable (#6922)

Kuba Werłos 1 год назад
Родитель
Сommit
f38ecb126c

+ 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?$}isx',
+                '{^(?:\s*\*|/\*\*)\s*@'.$name.'\s+'.TypeExpression::REGEX_TYPES.'(?:(?:[*\h\v]|\&?[\.\$]).*)?\r?$}isx',
                 $this->lines[0]->getContent(),
                 $matches
             );

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

@@ -52,7 +52,7 @@ function foo ($bar) {}
     /**
      * {@inheritdoc}
      *
-     * Must run before PhpdocAlignFixer, PhpdocTypesFixer, PhpdocTypesOrderFixer.
+     * Must run before PhpdocAlignFixer.
      * Must run after AlignMultilineCommentFixer, CommentToPhpdocFixer, PhpdocIndentFixer, PhpdocToCommentFixer.
      */
     public function getPriority(): int

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

@@ -131,7 +131,7 @@ final class PhpdocTypesFixer extends AbstractPhpdocTypesFixer implements Configu
      * {@inheritdoc}
      *
      * Must run before GeneralPhpdocAnnotationRemoveFixer, GeneralPhpdocTagRenameFixer, NoBlankLinesAfterPhpdocFixer, NoEmptyPhpdocFixer, NoSuperfluousPhpdocTagsFixer, PhpdocAddMissingParamAnnotationFixer, PhpdocAlignFixer, PhpdocInlineTagNormalizerFixer, PhpdocLineSpanFixer, PhpdocNoAccessFixer, PhpdocNoAliasTagFixer, PhpdocNoEmptyReturnFixer, PhpdocNoPackageFixer, PhpdocNoUselessInheritdocFixer, PhpdocOrderByValueFixer, PhpdocOrderFixer, PhpdocReturnSelfReferenceFixer, PhpdocScalarFixer, PhpdocSeparationFixer, PhpdocSingleLineVarSpacingFixer, PhpdocSummaryFixer, PhpdocTagCasingFixer, PhpdocTagTypeFixer, PhpdocToParamTypeFixer, PhpdocToPropertyTypeFixer, PhpdocToReturnTypeFixer, PhpdocTrimConsecutiveBlankLineSeparationFixer, PhpdocTrimFixer, PhpdocTypesOrderFixer, PhpdocVarAnnotationCorrectOrderFixer, PhpdocVarWithoutNameFixer.
-     * Must run after PhpdocAnnotationWithoutDotFixer, PhpdocIndentFixer.
+     * Must run after PhpdocIndentFixer.
      */
     public function getPriority(): int
     {

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

@@ -92,7 +92,7 @@ final class PhpdocTypesOrderFixer extends AbstractFixer implements ConfigurableF
      * {@inheritdoc}
      *
      * Must run before PhpdocAlignFixer.
-     * Must run after AlignMultilineCommentFixer, CommentToPhpdocFixer, PhpdocAnnotationWithoutDotFixer, PhpdocIndentFixer, PhpdocScalarFixer, PhpdocToCommentFixer, PhpdocTypesFixer.
+     * Must run after AlignMultilineCommentFixer, CommentToPhpdocFixer, PhpdocIndentFixer, PhpdocScalarFixer, PhpdocToCommentFixer, PhpdocTypesFixer.
      */
     public function getPriority(): int
     {

+ 0 - 4
tests/AutoReview/FixerFactoryTest.php

@@ -685,10 +685,6 @@ final class FixerFactoryTest extends TestCase
                 'phpdoc_align',
                 'phpdoc_order',
             ],
-            'phpdoc_annotation_without_dot' => [
-                'phpdoc_types',
-                'phpdoc_types_order',
-            ],
             'phpdoc_line_span' => [
                 'no_superfluous_phpdoc_tags',
             ],

+ 1 - 0
tests/DocBlock/AnnotationTest.php

@@ -504,6 +504,7 @@ final class AnnotationTest extends TestCase
             [['bool', 'int'], '* @param bool|int ...$foo'],
             [['bool', 'int'], '* @param bool|int &$foo'],
             [['bool', 'int'], '* @param bool|int &...$foo'],
+            [['bool', 'int'], '* @param bool|int$foo'],
             [['bool', 'int'], '* @param bool|int&$foo'],
             [['bool', 'int'], '* @param bool|int&...$foo'],
             [['bar', 'baz', 'foo'], '* @param Foo|Bar&Baz&$param'],

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

@@ -264,6 +264,11 @@ final class PhpdocTypesFixerTest extends AbstractFixerTestCase
                     * @return array{FOO: BOOL, NULL: NULL|INT, BAR: STRING|BAZ}
                     */',
         ];
+
+        yield 'no space between type and variable' => [
+            '<?php /** @param null|string$foo */',
+            '<?php /** @param NULL|STRING$foo */',
+        ];
     }
 
     public function testWrongConfig(): void

+ 4 - 0
tests/Fixer/Phpdoc/PhpdocTypesOrderFixerTest.php

@@ -178,6 +178,10 @@ final class PhpdocTypesOrderFixerTest extends AbstractFixerTestCase
                 '<?php /** @param null|callable(null|foo, null|bar): array<string, T> $callback */',
                 '<?php /** @param null|callable(foo|null, bar|null): array<string, T> $callback */',
             ],
+            [
+                '<?php /** @param null|string$foo */',
+                '<?php /** @param string|null$foo */',
+            ],
         ];
     }
 

+ 0 - 31
tests/Fixtures/Integration/priority/phpdoc_annotation_without_dot,phpdoc_types.test

@@ -1,31 +0,0 @@
---TEST--
-Integration of fixers: phpdoc_annotation_without_dot,phpdoc_types.
---RULESET--
-{"phpdoc_annotation_without_dot": true, "phpdoc_types": true}
---EXPECT--
-<?php
-
-class Foo
-{
-    /**
-     * @return int[]|string[]|null[]
-     */
-    public function Az()
-    {
-        return[];
-    }
-}
-
---INPUT--
-<?php
-
-class Foo
-{
-    /**
-     * @return int[]|string[]|NULL[].
-     */
-    public function Az()
-    {
-        return[];
-    }
-}

+ 0 - 31
tests/Fixtures/Integration/priority/phpdoc_annotation_without_dot,phpdoc_types_order.test

@@ -1,31 +0,0 @@
---TEST--
-Integration of fixers: phpdoc_annotation_without_dot,phpdoc_types_order.
---RULESET--
-{"phpdoc_annotation_without_dot": true, "phpdoc_types_order": true}
---EXPECT--
-<?php
-
-class Foo
-{
-    /**
-     * @return int[]|NULL[]|string[]
-     */
-    public function Az()
-    {
-        return[];
-    }
-}
-
---INPUT--
-<?php
-
-class Foo
-{
-    /**
-     * @return int[]|string[]|NULL[].
-     */
-    public function Az()
-    {
-        return[];
-    }
-}