Skip to content

Commit 9702fbb

Browse files
committed
PhpdocVarAnnotationCorrectOrderFixer: handle types with whitespace inside
1 parent 28a4bd0 commit 9702fbb

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/Fixer/PhpdocVarAnnotationCorrectOrderFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function fix(\SplFileInfo $file, Tokens $tokens) : void
3939
}
4040

4141
$newContent = \preg_replace(
42-
'/(@var\s*)(\$\S+)(\s+)([^\$]\S*)(\s|\*)/i',
42+
'/(@var\s*)(\$\S+)(\s+)([^\$](?:[^<\s]|<[^>]*>)*)(\s|\*)/i',
4343
'$1$4$3$2$5',
4444
$token->getContent()
4545
);

tests/Fixer/PhpdocVarAnnotationCorrectOrderFixerTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,33 @@ public function provideFixCases() : \Iterator
119119
',
120120
'<?php
121121
/** @var $someWeirdLongNAME__123 Foo|Bar|mixed|int */
122+
',
123+
];
124+
125+
yield [
126+
'<?php
127+
/** @var array<int, int> $foo */
128+
',
129+
'<?php
130+
/** @var $foo array<int, int> */
131+
',
132+
];
133+
134+
yield [
135+
'<?php
136+
/** @var array<int, int> $foo Array of something */
137+
',
138+
'<?php
139+
/** @var $foo array<int, int> Array of something */
140+
',
141+
];
142+
143+
yield [
144+
'<?php
145+
/** @var Foo|array<int, int>|null $foo */
146+
',
147+
'<?php
148+
/** @var $foo Foo|array<int, int>|null */
122149
',
123150
];
124151
}

0 commit comments

Comments
 (0)