Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ final class RemovePropertyVariableNameDescriptionFixer extends AbstractSymplifyF
*/
private const ERROR_MESSAGE = 'Remove useless "$variable" from @var tag';

/**
* @var string
* @see https://regex101.com/r/2PxeKF/1
*/
private const VAR_REGEX = '#@(?:psalm-|phpstan-)?var#';

private readonly PropertyNameResolver $propertyNameResolver;

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

$docblockLines = explode("\n", $originalDocContent);
foreach ($docblockLines as $key => $docblockLine) {
if (! str_contains($docblockLine, '@var')) {
if (! str_ends_with($docblockLine, ' ' . $propertyName)) {
continue;
}

if (! str_ends_with($docblockLine, ' ' . $propertyName)) {
if (! preg_match(self::VAR_REGEX, $docblockLine)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Symplify\CodingStandard\Tests\Fixer\Annotation\RemovePropertyVariableNameDescriptionFixer\Fixture;

final class PhpstanAnnotation
{
/**
* @phpstan-var string $name
*/
public $name;
}

?>
-----
<?php

namespace Symplify\CodingStandard\Tests\Fixer\Annotation\RemovePropertyVariableNameDescriptionFixer\Fixture;

final class PhpstanAnnotation
{
/**
* @phpstan-var string
*/
public $name;
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Symplify\CodingStandard\Tests\Fixer\Annotation\RemovePropertyVariableNameDescriptionFixer\Fixture;

final class PsalmAnnotation
{
/**
* @psalm-var string $name
*/
public $name;
}

?>
-----
<?php

namespace Symplify\CodingStandard\Tests\Fixer\Annotation\RemovePropertyVariableNameDescriptionFixer\Fixture;

final class PsalmAnnotation
{
/**
* @psalm-var string
*/
public $name;
}

?>