Skip to content

Commit

Permalink
bug #5835 PhpdocTypesOrderFixer: fix for array shapes (kubawerlos)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.0 branch.

Discussion
----------

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>`.

Commits
-------

5669a31 PhpdocTypesOrderFixer: fix for array shapes
  • Loading branch information
keradus committed Aug 3, 2021
2 parents 6ba52ba + 5669a31 commit a8897f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/Fixer/Phpdoc/PhpdocTypesOrderFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>}> */',
],
];
}

Expand Down

0 comments on commit a8897f2

Please sign in to comment.