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

Issue:
[3.0 dev] `phpdoc_types_order` does not work together with array shapes
## Bug report

### Code snippet that reproduces the problem

```php
    /**
     * @return array<array{level:string, message:string, context:array<mixed>}>
     */
    public function getLogs(?string $level = null) : array
    {
    }
```

```
PHP CS Fixer 3.0.1-DEV Constitution by Fabien Potencier and Dariusz Ruminski
Runtime: PHP 8.0.7
Loaded config default from "/Volumes/CS/www/website/.php-cs-fixer.php".
Using cache file "var/.php_cs.cache".
Paths from configuration file have been overridden by paths provided as command arguments.
F                                                                                                                            1 / 1 (100%)
Legend: ?-unknown, I-invalid file syntax (file ignored), S-skipped (cached or empty file), .-no changes, F-fixed, E-error
   1) /Volumes/CS/www/website/src-dev/Testing/Logging/InMemorLogger.php (phpdoc_types_order)
      ---------- begin diff ----------
--- /Volumes/CS/www/website/src-dev/Testing/Logging/InMemorLogger.php
+++ /Volumes/CS/www/website/src-dev/Testing/Logging/InMemorLogger.php
@@ -97,7 +97,7 @@
     }

     /**
-     * @return array<array{level:string, message:string, context:array<mixed>}>
+     * @return array<array{level:string, message:string, context:array<mixed>|}>
      */
     public function getLogs(?string $level = null) : array
     {

      ----------- end diff -----------


Checked all files in 0.085 seconds, 18.000 MB memory used
exit status 8
```



Pull request description:
PhpdocTypesOrderFixer: fix for array shapes
fixes #5798 
closes #5833

As an extra it will "work" for broken types such as  `array<string}` or `array{string>`.

Patch:
diff --git a/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php b/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php
index 258758c86..718e86fc0 100644
--- a/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php
+++ b/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php
@@ -211,7 +211,7 @@ static function (string $typeA, string $typeB) {
     private function sortJoinedTypes(string $types): string
     {
         $types = array_filter(
-            Preg::split('/([^|<]+(?:<.*>)?)/', $types, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY),
+            Preg::split('/([^|<{]+(?:[<{].*[>}])?)/', $types, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY),
             static function (string $value) {
                 return '|' !== $value;
             }


Test patch:
diff --git a/tests/Fixer/Phpdoc/PhpdocTypesOrderFixerTest.php b/tests/Fixer/Phpdoc/PhpdocTypesOrderFixerTest.php
index 78ad0fff3..bf45c37c7 100644
--- a/tests/Fixer/Phpdoc/PhpdocTypesOrderFixerTest.php
+++ b/tests/Fixer/Phpdoc/PhpdocTypesOrderFixerTest.php
@@ -144,6 +144,18 @@ public function provideFixCases()
             [
                 '<?php /** @var array<array<int, int>, OutputInterface> */',
             ],
+            [
+                '<?php /** @var iterable<array{names:array<string>, surname:string}> */',
+            ],
+            [
+                '<?php /** @var iterable<array{surname:string, names:array<string>}> */',
+            ],
+            [
+                '<?php /** @return array<array{level:string, message:string, context:array<mixed>}> */',
+            ],
+            [
+                '<?php /** @return Data<array{enabled: string[], all: array<string, string>}> */',
+            ],
         ];
     }