Skip to content

Commit 322c850

Browse files
committed
RemovePropertyVariableNameDescriptionFixer: Support prefixed @var
1 parent 5734157 commit 322c850

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

src/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ final class RemovePropertyVariableNameDescriptionFixer extends AbstractSymplifyF
2424
*/
2525
private const ERROR_MESSAGE = 'Remove useless "$variable" from @var tag';
2626

27+
/**
28+
* @var string
29+
* @see https://regex101.com/r/2PxeKF/1
30+
*/
31+
private const VAR_REGEX = '#@(?:psalm-|phpstan-)?var#';
32+
33+
2734
private readonly PropertyNameResolver $propertyNameResolver;
2835

2936
public function __construct(
@@ -73,11 +80,11 @@ public function fix(SplFileInfo $fileInfo, Tokens $tokens): void
7380

7481
$docblockLines = explode("\n", $originalDocContent);
7582
foreach ($docblockLines as $key => $docblockLine) {
76-
if (! str_contains($docblockLine, '@var')) {
83+
if (! str_ends_with($docblockLine, ' ' . $propertyName)) {
7784
continue;
7885
}
7986

80-
if (! str_ends_with($docblockLine, ' ' . $propertyName)) {
87+
if (!preg_match(self::VAR_REGEX, $docblockLine)) {
8188
continue;
8289
}
8390

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Symplify\CodingStandard\Tests\Fixer\Annotation\RemovePropertyVariableNameDescriptionFixer\Fixture;
4+
5+
final class PhpstanAnnotation
6+
{
7+
/**
8+
* @phpstan-var string $name
9+
*/
10+
public $name;
11+
}
12+
13+
?>
14+
-----
15+
<?php
16+
17+
namespace Symplify\CodingStandard\Tests\Fixer\Annotation\RemovePropertyVariableNameDescriptionFixer\Fixture;
18+
19+
final class PhpstanAnnotation
20+
{
21+
/**
22+
* @phpstan-var string
23+
*/
24+
public $name;
25+
}
26+
27+
?>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Symplify\CodingStandard\Tests\Fixer\Annotation\RemovePropertyVariableNameDescriptionFixer\Fixture;
4+
5+
final class PsalmAnnotation
6+
{
7+
/**
8+
* @psalm-var string $name
9+
*/
10+
public $name;
11+
}
12+
13+
?>
14+
-----
15+
<?php
16+
17+
namespace Symplify\CodingStandard\Tests\Fixer\Annotation\RemovePropertyVariableNameDescriptionFixer\Fixture;
18+
19+
final class PsalmAnnotation
20+
{
21+
/**
22+
* @psalm-var string
23+
*/
24+
public $name;
25+
}
26+
27+
?>

0 commit comments

Comments
 (0)