Skip to content

Commit bae6dfb

Browse files
committed
Add fix
1 parent 7c915e5 commit bae6dfb

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

README.md

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

643643
#### PhpdocTypesCommaSpacesFixer
644-
PHPDoc types commas must not be preceded by a whitespace, and must be succeeded by a single whitespace.
644+
PHPDoc types commas must not be preceded by a whitespace, and must be succeeded by a single whitespace or newline.
645645
```diff
646646
-<?php /** @var array<int,string> */
647647
+<?php /** @var array<int, string> */

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
}

0 commit comments

Comments
 (0)