diff --git a/CakePHP/Sniffs/Commenting/TypeHintSniff.php b/CakePHP/Sniffs/Commenting/TypeHintSniff.php index 726d2fc..7036168 100644 --- a/CakePHP/Sniffs/Commenting/TypeHintSniff.php +++ b/CakePHP/Sniffs/Commenting/TypeHintSniff.php @@ -243,9 +243,10 @@ protected function getSortedTypeHint(array $types): string */ protected function renderUnionTypes(array $typeNodes): string { + // Remove parenthesis added by phpstan around union and intersection types return preg_replace( - ['/ ([\|&]) /', '/<\(/', '/\)>/'], - ['${1}', '<', '>'], + ['/ ([\|&]) /', '/<\(/', '/\)>/', '/\), /', '/, \(/'], + ['${1}', '<', '>', ', ', ', '], implode('|', $typeNodes) ); } diff --git a/CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc b/CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc index 8195085..e0bfd7b 100644 --- a/CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc +++ b/CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc @@ -36,4 +36,7 @@ function test() /** @psalm-var null|scalar|class-string<\Cake\I18n\Number>|array $testVar2 */ $testVar2; + + /** @var string|null|array|string|null>|string|null> + $arrays; } diff --git a/CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc.fixed b/CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc.fixed index 8dab2c4..1de1a4a 100644 --- a/CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc.fixed +++ b/CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc.fixed @@ -36,4 +36,7 @@ function test() /** @psalm-var array|class-string<\Cake\I18n\Number>|scalar|null $testVar2 */ $testVar2; + + /** @var array|string|null>|string|null>|string|null + $arrays; } diff --git a/CakePHP/Tests/Commenting/TypeHintUnitTest.php b/CakePHP/Tests/Commenting/TypeHintUnitTest.php index db0affd..e316348 100644 --- a/CakePHP/Tests/Commenting/TypeHintUnitTest.php +++ b/CakePHP/Tests/Commenting/TypeHintUnitTest.php @@ -32,6 +32,7 @@ public function getWarningList($testFile = '') 24 => 1, 25 => 1, 37 => 1, + 40 => 1, ]; default: