Skip to content

Commit

Permalink
feat: PhpdocTypesOrderFixer Support DNF types (#7732)
Browse files Browse the repository at this point in the history
Co-authored-by: Greg Korba <greg@codito.dev>
  • Loading branch information
smnandre and Wirone committed Jan 16, 2024
1 parent 7144d50 commit 1d34bb2
Show file tree
Hide file tree
Showing 2 changed files with 31 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 @@ -169,7 +169,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
*/
private function sortTypes(TypeExpression $typeExpression): array
{
$normalizeType = static fn (string $type): string => Preg::replace('/^\\??\\\?/', '', $type);
$normalizeType = static fn (string $type): string => Preg::replace('/^\(*\??\\\?/', '', $type);

$typeExpression->sortTypes(
function (TypeExpression $a, TypeExpression $b) use ($normalizeType): int {
Expand Down
30 changes: 30 additions & 0 deletions tests/Fixer/Phpdoc/PhpdocTypesOrderFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,36 @@ public static function provideFixWithAlphaAlgorithmCases(): iterable
'<?php /** @return A&B<X|Y|Z>&C&D */',
'<?php /** @return A&D&B<X|Y|Z>&C */',
];

yield [
'<?php /** @param A|(B&C) */',
'<?php /** @param (C&B)|A */',
];

yield [
'<?php /** @param A|((A&B)|(B&C)) */',
'<?php /** @param ((B&C)|(B&A))|A */',
];

yield [
'<?php /** @param A&(B&C) */',
'<?php /** @param (C&B)&A */',
];

yield [
'<?php /** @param (A&C)|(B&C)|(C&D) */',
'<?php /** @param (C&A)|(C&B)|(C&D) */',
];

yield [
'<?php /** @param \A|(\B&\C)|D */',
'<?php /** @param D|\A|(\C&\B) */',
];

yield [
'<?php /** @param A|((B&C)|D) */',
'<?php /** @param (D|(C&B))|A */',
];
}

/**
Expand Down

0 comments on commit 1d34bb2

Please sign in to comment.