From 8b8eca0a5ae5a11b7d61b0bd56f8744c52dd6747 Mon Sep 17 00:00:00 2001 From: Laurent Clouet Date: Mon, 21 Oct 2019 19:22:44 +0000 Subject: [PATCH] PhpdocTypesOrderFixer - Prevent unexpected default value change --- src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php | 4 ++-- tests/Fixer/Phpdoc/PhpdocTypesOrderFixerTest.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php b/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php index f11fec8a4b1..ab6a7ff53ef 100644 --- a/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php +++ b/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php @@ -132,8 +132,8 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) // 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.')'; diff --git a/tests/Fixer/Phpdoc/PhpdocTypesOrderFixerTest.php b/tests/Fixer/Phpdoc/PhpdocTypesOrderFixerTest.php index 0d99aa932b0..d2be9ed8721 100644 --- a/tests/Fixer/Phpdoc/PhpdocTypesOrderFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocTypesOrderFixerTest.php @@ -141,6 +141,10 @@ public function provideFixCases() '\') */', + '\') */', + ], ]; }