Skip to content

Commit 7c3d422

Browse files
authored
PhpdocNoIncorrectVarAnnotationFixer - keep string literals (#1096)
1 parent 4d168ea commit 7c3d422

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/Fixer/PhpdocNoIncorrectVarAnnotationFixer.php

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

6767
// remove ones not having type at the beginning
68-
self::removeVarAnnotationNotMatchingPattern($tokens, $index, '/@var\\s+[\\?\\\\a-zA-Z_\\x7f-\\xff]/');
68+
self::removeVarAnnotationNotMatchingPattern($tokens, $index, '/@var\\s+[\\?\\\\a-zA-Z_\\x7f-\\xff\'"]/');
6969

7070
$nextIndex = self::getIndexAfterPhpDoc($tokens, $index);
7171

tests/Fixer/PhpdocNoIncorrectVarAnnotationFixerTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,33 @@ class Foo
257257
}',
258258
];
259259

260+
yield 'keep string literals' => [
261+
<<<'PHP'
262+
<?php class Foo
263+
{
264+
/**
265+
* @var 'foo'
266+
*/
267+
public string $a;
268+
269+
/**
270+
* @var 'foo'|'bar'|'baz'
271+
*/
272+
protected string $b;
273+
274+
/**
275+
* @var 'foo'|'foo-with-dashes'|'bar'|'baz'|null
276+
*/
277+
private ?string $c;
278+
279+
/**
280+
* @var "in-double-quotes"|null
281+
*/
282+
public ?string $d;
283+
}
284+
PHP,
285+
];
286+
260287
yield 'remove PHPDoc for class properties' => [
261288
'<?php
262289
class Foo

0 commit comments

Comments
 (0)