Browse Source

PhpdocTypesOrderFixer - Prevent unexpected default value change

Laurent Clouet 5 years ago
parent
commit
8b8eca0a5a

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

@@ -132,8 +132,8 @@ final class PhpdocTypesOrderFixer extends AbstractFixer implements Configuration
                 // fix @method parameters types
                 $line = $doc->getLine($annotation->getStart());
                 $line->setContent(Preg::replaceCallback('/(@method\s+.+?\s+\w+\()(.*)\)/', function (array $matches) {
-                    $sorted = Preg::replaceCallback('/((?:^|,)\s*)([^\s]+)/', function (array $matches) {
-                        return $matches[1].$this->sortJoinedTypes($matches[2]);
+                    $sorted = Preg::replaceCallback('/([^\s,]+)([\s]+\$[^\s,]+)/', function (array $matches) {
+                        return $this->sortJoinedTypes($matches[1]).$matches[2];
                     }, $matches[2]);
 
                     return $matches[1].$sorted.')';

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

@@ -141,6 +141,10 @@ final class PhpdocTypesOrderFixerTest extends AbstractFixerTestCase
                 '<?php /** @var null|Foo[]|Foo|Foo\Bar|Foo_Bar */',
                 '<?php /** @var Foo[]|null|Foo|Foo\Bar|Foo_Bar */',
             ],
+            [
+                '<?php /** @method void bar(null|string $delimiter = \',<br/>\') */',
+                '<?php /** @method void bar(string|null $delimiter = \',<br/>\') */',
+            ],
         ];
     }