Browse Source

PhpdocTypesOrderFixer - handle complex keys

Andrei Tcaci 3 years ago
parent
commit
f0337f45ff

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

@@ -163,7 +163,7 @@ final class PhpdocTypesOrderFixer extends AbstractFixer implements Configuration
     private function sortTypes(array $types)
     {
         foreach ($types as $index => $type) {
-            $types[$index] = Preg::replaceCallback('/^([^<]+)<(?:([\w\|]+?)(,\s*))?(.*)>$/', function (array $matches) {
+            $types[$index] = Preg::replaceCallback('/^([^<]+)<(?:([\w\|]+?|<?.*>)(,\s*))?(.*)>$/', function (array $matches) {
                 return $matches[1].'<'.$this->sortJoinedTypes($matches[2]).$matches[3].$this->sortJoinedTypes($matches[4]).'>';
             }, $type);
         }

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

@@ -145,6 +145,9 @@ final class PhpdocTypesOrderFixerTest extends AbstractFixerTestCase
                 '<?php /** @method void bar(null|string $delimiter = \',<br/>\') */',
                 '<?php /** @method void bar(string|null $delimiter = \',<br/>\') */',
             ],
+            [
+                '<?php /** @var array<array<int, int>, OutputInterface> */',
+            ],
         ];
     }