Skip to content

Commit

Permalink
PhpdocTypesOrderFixer - Prevent unexpected default value change
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent35240 authored and keradus committed Nov 2, 2019
1 parent f031f23 commit 8b8eca0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php
Expand Up @@ -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.')';
Expand Down
4 changes: 4 additions & 0 deletions tests/Fixer/Phpdoc/PhpdocTypesOrderFixerTest.php
Expand Up @@ -141,6 +141,10 @@ public function provideFixCases()
'<?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/>\') */',
],
];
}

Expand Down

0 comments on commit 8b8eca0

Please sign in to comment.