Skip to content

Commit 614b3b3

Browse files
committed
Merge branch 'main' into add_FunctionParameterSeparationFixer
2 parents 336dd96 + 322d0e0 commit 614b3b3

File tree

7 files changed

+52
-9
lines changed

7 files changed

+52
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## v3.32.0
44
- Add FunctionParameterSeparationFixer
5+
- Update minimum PHP CS Fixer version to 3.85.0
56

67
## v3.31.0
78
- Update minimum PHP CS Fixer version to 3.84.0

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ PHPDoc `list` type must be used instead of `array` without a key.
659659
```
660660

661661
#### PhpdocTypesCommaSpacesFixer
662-
PHPDoc types commas must not be preceded by a whitespace, and must be succeeded by a single whitespace.
662+
PHPDoc types commas must not be preceded by a whitespace, and must be succeeded by a single whitespace or newline.
663663
```diff
664664
-<?php /** @var array<int,string> */
665665
+<?php /** @var array<int, string> */

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"php": "^7.4 || ^8.0",
1414
"ext-filter": "*",
1515
"ext-tokenizer": "*",
16-
"friendsofphp/php-cs-fixer": "^3.84"
16+
"friendsofphp/php-cs-fixer": "^3.85"
1717
},
1818
"require-dev": {
1919
"phpunit/phpunit": "^9.6.22 || 10.5.45 || ^11.5.7"

src/Fixer/AbstractTypesFixer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ final public function fix(\SplFileInfo $file, Tokens $tokens): void
4444
continue;
4545
}
4646

47-
$typeExpression = $annotation->getTypeExpression();
48-
if ($typeExpression === null) {
47+
$types = $annotation->getTypes();
48+
if ($types === []) {
4949
continue;
5050
}
5151

52-
$type = $typeExpression->toString();
53-
$type = $this->fixType($type);
54-
$annotation->setTypes([$type]);
52+
$types = \array_map(fn (string $x): string => $this->fixType($x), $types);
53+
54+
$annotation->setTypes($types);
5555
}
5656

5757
$newContent = $docBlock->getContent();

src/Fixer/PhpdocTypesCommaSpacesFixer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class PhpdocTypesCommaSpacesFixer extends AbstractTypesFixer
2424
public function getDefinition(): FixerDefinitionInterface
2525
{
2626
return new FixerDefinition(
27-
'PHPDoc types commas must not be preceded by a whitespace, and must be succeeded by a single whitespace.',
27+
'PHPDoc types commas must not be preceded by a whitespace, and must be succeeded by a single whitespace or newline.',
2828
[new CodeSample("<?php /** @var array<int,string> */\n")],
2929
'',
3030
);
@@ -37,6 +37,6 @@ public function getPriority(): int
3737

3838
protected function fixType(string $type): string
3939
{
40-
return Preg::replace('/\\h*,\\s*/', ', ', $type);
40+
return Preg::replace('/,(?!\\R)\\s*/', ', ', Preg::replace('/\\h*,/', ',', $type));
4141
}
4242
}

tests/Fixer/PhpdocTypesCommaSpacesFixerTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,26 @@ public static function provideFixCases(): iterable
105105
* @return array<string,Foo> Description having "," should not be touched
106106
*/',
107107
];
108+
109+
yield [
110+
<<<'PHP'
111+
<?php
112+
/**
113+
* @return array{
114+
* foo: bool,
115+
* bar: null|string,
116+
* }
117+
*/
118+
PHP,
119+
<<<'PHP'
120+
<?php
121+
/**
122+
* @return array{
123+
* foo: bool ,
124+
* bar: null|string ,
125+
* }
126+
*/
127+
PHP,
128+
];
108129
}
109130
}

tests/Fixer/PhpdocTypesTrimFixerTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,5 +257,26 @@ function fooBar($x, $y) {}
257257
function baz() {}
258258
',
259259
];
260+
261+
yield [
262+
<<<'PHP'
263+
<?php
264+
/**
265+
* @return array{
266+
* foo: null|bool,
267+
* bar: string|null,
268+
* }
269+
*/
270+
PHP,
271+
<<<'PHP'
272+
<?php
273+
/**
274+
* @return array{
275+
* foo: null | bool,
276+
* bar: string | null,
277+
* }
278+
*/
279+
PHP,
280+
];
260281
}
261282
}

0 commit comments

Comments
 (0)