Skip to content

Commit e5a5093

Browse files
clxmstaabstaabm
andauthored
RemovePropertyVariableNameDescriptionFixer: Support prefixed @var (#70)
* RemovePropertyVariableNameDescriptionFixer: Support prefixed `@var` * Update RemovePropertyVariableNameDescriptionFixer.php --------- Co-authored-by: Markus Staab <markus.staab@redaxo.de>
1 parent 5734157 commit e5a5093

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

src/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ 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+
2733
private readonly PropertyNameResolver $propertyNameResolver;
2834

2935
public function __construct(
@@ -73,11 +79,11 @@ public function fix(SplFileInfo $fileInfo, Tokens $tokens): void
7379

7480
$docblockLines = explode("\n", $originalDocContent);
7581
foreach ($docblockLines as $key => $docblockLine) {
76-
if (! str_contains($docblockLine, '@var')) {
82+
if (! str_ends_with($docblockLine, ' ' . $propertyName)) {
7783
continue;
7884
}
7985

80-
if (! str_ends_with($docblockLine, ' ' . $propertyName)) {
86+
if (! preg_match(self::VAR_REGEX, $docblockLine)) {
8187
continue;
8288
}
8389

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)