Repository: FriendsOfPHP/PHP-CS-Fixer (php)

Issue:
PhpdocTypesOrderFixer false positive
The fixer wants to update this:

```
	/**
	 * @return MultiMap<CompositeKey<Identity, ScalarKey>, CompensationAllocation>
	 */
```

to this:

```
	/**
	 * @return MultiMap<CompositeKey<Identity, ScalarKey>|, CompensationAllocation>
	 */
```

Pull request description:
PhpdocTypesOrderFixer - handle complex keys
Fixes #5116 

Patch:
diff --git a/doc/rules/class_notation/final_internal_class.rst b/doc/rules/class_notation/final_internal_class.rst
index eb9ddb2c2..a999b4778 100644
--- a/doc/rules/class_notation/final_internal_class.rst
+++ b/doc/rules/class_notation/final_internal_class.rst
@@ -33,7 +33,7 @@ of the white list ones are used as well. (case insensitive)
 
 Allowed types: ``array``
 
-Default value: ``['@final', '@Entity', '@ORM\\Entity', '@ORM\\Mapping\\Entity', '@Mapping\\Entity', '@Document', '@ODM\\Document']``
+Default value: ``['@final', '@Entity', '@ORM\\Entity', '@ORM\\Mapping\\Entity', '@Mapping\\Entity']``
 
 ``consider_absent_docblock_as_internal_class``
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/src/Fixer/ClassNotation/FinalInternalClassFixer.php b/src/Fixer/ClassNotation/FinalInternalClassFixer.php
index 91a630e09..8154848bd 100644
--- a/src/Fixer/ClassNotation/FinalInternalClassFixer.php
+++ b/src/Fixer/ClassNotation/FinalInternalClassFixer.php
@@ -169,8 +169,6 @@ protected function createConfigurationDefinition()
                     '@ORM\Entity',
                     '@ORM\Mapping\Entity',
                     '@Mapping\Entity',
-                    '@Document',
-                    '@ODM\Document',
                 ])
                 ->setNormalizer($annotationsNormalizer)
                 ->getOption(),
diff --git a/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php b/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php
index 5b3ea0c7e..660c523b7 100644
--- a/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php
+++ b/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php
@@ -163,7 +163,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
     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);
         }


Test patch:
diff --git a/tests/Fixer/ClassNotation/FinalClassFixerTest.php b/tests/Fixer/ClassNotation/FinalClassFixerTest.php
index b4d82d1b6..c9513694c 100644
--- a/tests/Fixer/ClassNotation/FinalClassFixerTest.php
+++ b/tests/Fixer/ClassNotation/FinalClassFixerTest.php
@@ -41,8 +41,6 @@ public function provideFixCases()
             ['<?php use Doctrine\ORM\Mapping as ORM; /** @ORM\Entity */ class MyEntity {}'],
             ['<?php use Doctrine\ORM\Mapping; /** @Mapping\Entity */ class MyEntity {}'],
             ['<?php use Doctrine\ORM; /** @ORM\Mapping\Entity */ class MyEntity {}'],
-            ['<?php /** @Document */ class MyDocument {}'],
-            ['<?php use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; /** @ODM\Document */ class MyEntity {}'],
             ['<?php /** @entity */ class MyEntity {}'],
             ['<?php use Doctrine\ORM\Mapping as ORM; /** @orm\entity */ class MyEntity {}'],
             ['<?php abstract class MyAbstract {}'],
diff --git a/tests/Fixer/Phpdoc/PhpdocTypesOrderFixerTest.php b/tests/Fixer/Phpdoc/PhpdocTypesOrderFixerTest.php
index d2be9ed87..5153566b9 100644
--- a/tests/Fixer/Phpdoc/PhpdocTypesOrderFixerTest.php
+++ b/tests/Fixer/Phpdoc/PhpdocTypesOrderFixerTest.php
@@ -145,6 +145,9 @@ public function provideFixCases()
                 '<?php /** @method void bar(null|string $delimiter = \',<br/>\') */',
                 '<?php /** @method void bar(string|null $delimiter = \',<br/>\') */',
             ],
+            [
+                '<?php /** @var array<array<int, int>, OutputInterface> */',
+            ],
         ];
     }