diff --git a/CHANGELOG.md b/CHANGELOG.md index 41faf193..4182de86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # CHANGELOG for PHP CS Fixer: custom fixers +## v3.32.0 +- Update minimum PHP CS Fixer version to 3.85.0 + ## v3.31.0 - Update minimum PHP CS Fixer version to 3.84.0 diff --git a/README.md b/README.md index 0deb922c..b565ae4b 100644 --- a/README.md +++ b/README.md @@ -641,7 +641,7 @@ PHPDoc `list` type must be used instead of `array` without a key. ``` #### PhpdocTypesCommaSpacesFixer -PHPDoc types commas must not be preceded by a whitespace, and must be succeeded by a single whitespace. +PHPDoc types commas must not be preceded by a whitespace, and must be succeeded by a single whitespace or newline. ```diff - */ + */ diff --git a/composer.json b/composer.json index dd389821..11dfa4c7 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "php": "^7.4 || ^8.0", "ext-filter": "*", "ext-tokenizer": "*", - "friendsofphp/php-cs-fixer": "^3.84" + "friendsofphp/php-cs-fixer": "^3.85" }, "require-dev": { "phpunit/phpunit": "^9.6.22 || 10.5.45 || ^11.5.7" diff --git a/src/Fixer/AbstractTypesFixer.php b/src/Fixer/AbstractTypesFixer.php index 509b40a0..259fbd5f 100644 --- a/src/Fixer/AbstractTypesFixer.php +++ b/src/Fixer/AbstractTypesFixer.php @@ -44,14 +44,14 @@ final public function fix(\SplFileInfo $file, Tokens $tokens): void continue; } - $typeExpression = $annotation->getTypeExpression(); - if ($typeExpression === null) { + $types = $annotation->getTypes(); + if ($types === []) { continue; } - $type = $typeExpression->toString(); - $type = $this->fixType($type); - $annotation->setTypes([$type]); + $types = \array_map(fn (string $x): string => $this->fixType($x), $types); + + $annotation->setTypes($types); } $newContent = $docBlock->getContent(); diff --git a/src/Fixer/PhpdocTypesCommaSpacesFixer.php b/src/Fixer/PhpdocTypesCommaSpacesFixer.php index ab7a9678..3f21d8da 100644 --- a/src/Fixer/PhpdocTypesCommaSpacesFixer.php +++ b/src/Fixer/PhpdocTypesCommaSpacesFixer.php @@ -24,7 +24,7 @@ final class PhpdocTypesCommaSpacesFixer extends AbstractTypesFixer public function getDefinition(): FixerDefinitionInterface { return new FixerDefinition( - 'PHPDoc types commas must not be preceded by a whitespace, and must be succeeded by a single whitespace.', + 'PHPDoc types commas must not be preceded by a whitespace, and must be succeeded by a single whitespace or newline.', [new CodeSample(" */\n")], '', ); @@ -37,6 +37,6 @@ public function getPriority(): int protected function fixType(string $type): string { - return Preg::replace('/\\h*,\\s*/', ', ', $type); + return Preg::replace('/,(?!\\R)\\s*/', ', ', Preg::replace('/\\h*,/', ',', $type)); } } diff --git a/tests/Fixer/PhpdocTypesCommaSpacesFixerTest.php b/tests/Fixer/PhpdocTypesCommaSpacesFixerTest.php index f4de9bf3..a489271f 100644 --- a/tests/Fixer/PhpdocTypesCommaSpacesFixerTest.php +++ b/tests/Fixer/PhpdocTypesCommaSpacesFixerTest.php @@ -105,5 +105,26 @@ public static function provideFixCases(): iterable * @return array Description having "," should not be touched */', ]; + + yield [ + <<<'PHP' +