Skip to content

Commit e3e1ab7

Browse files
authored
Merge pull request #94 from worksome/JIRA-16017_multi-line-array-shapes
fix: JIRA-16017 Resolve multi-line array shapes
2 parents 83d3f85 + b7748e0 commit e3e1ab7

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"rector/rector": "^2.0",
1414
"slevomat/coding-standard": "^8.16",
1515
"spaze/phpstan-disallowed-calls": "^4.4",
16-
"symplify/easy-coding-standard": "^12.5"
16+
"symplify/easy-coding-standard": "^12.6"
1717
},
1818
"require-dev": {
1919
"composer/composer": "^2.8",

src/PhpCsFixer/SpaceInGenericsFixer.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PhpCsFixer\FixerDefinition\CodeSample;
1010
use PhpCsFixer\FixerDefinition\FixerDefinition;
1111
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
12+
use PhpCsFixer\Preg;
1213
use PhpCsFixer\Tokenizer\Token;
1314
use PhpCsFixer\Tokenizer\Tokens;
1415
use SplFileInfo;
@@ -27,13 +28,7 @@ public function getDefinition(): FixerDefinitionInterface
2728

2829
protected function fixType(string $type): string
2930
{
30-
$newType = preg_replace('/\h*,\s*/', ', ', $type);
31-
32-
if ($newType === $type) {
33-
return $type;
34-
}
35-
36-
return $this->fixType($newType);
31+
return Preg::replace('/,(?!\\R)\\s*/', ', ', Preg::replace('/\\h*,/', ',', $type));
3732
}
3833

3934
public function fix(SplFileInfo $file, Tokens $tokens): void
@@ -50,13 +45,14 @@ public function fix(SplFileInfo $file, Tokens $tokens): void
5045
continue;
5146
}
5247

53-
$typeExpression = $annotation->getTypeExpression();
54-
if ($typeExpression === null) {
48+
$types = $annotation->getTypes();
49+
if ($types === []) {
5550
continue;
5651
}
5752

58-
$type = $this->fixType($typeExpression->toString());
59-
$annotation->setTypes([$type]);
53+
$types = \array_map(fn (string $x): string => $this->fixType($x), $types);
54+
55+
$annotation->setTypes($types);
6056
}
6157

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

tests/PhpCsFixer/SpaceInGenericsFixerTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,31 @@
8383
* @return array<string,Foo> Description having "," should not be touched
8484
*/',
8585
];
86+
87+
yield [
88+
'<?php /**
89+
* Multi-line array shapes are supported.
90+
*
91+
* @param array{
92+
* extensions?: array<int, class-string<ExtensionInterface>|ExtensionInterface>,
93+
* renderers?: array{
94+
* fenced?: array<int, class-string<NodeRendererInterface>|NodeRendererInterface>,
95+
* indented?: array<int, class-string<NodeRendererInterface>|NodeRendererInterface>
96+
* },
97+
* languages?: array<int, array{name: string, path: string, overwrite?: bool}>
98+
* }
99+
*/',
100+
'<?php /**
101+
* Multi-line array shapes are supported.
102+
*
103+
* @param array{
104+
* extensions?: array<int,class-string<ExtensionInterface>|ExtensionInterface>,
105+
* renderers?: array{
106+
* fenced?: array<int,class-string<NodeRendererInterface>|NodeRendererInterface>,
107+
* indented?: array<int,class-string<NodeRendererInterface>|NodeRendererInterface>
108+
* },
109+
* languages?: array<int,array{name: string, path: string, overwrite?: bool}>
110+
* }
111+
*/',
112+
];
86113
});

0 commit comments

Comments
 (0)