From 99211b0e1f7779da15f53ecdbe7782539c610bc9 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 18 Sep 2025 22:19:13 +0700 Subject: [PATCH] [AutoImport] Skip used at @see on UnusedImportRemovingPostRector --- .../PhpDocInfo/PhpDocInfo.php | 4 +++- .../PhpDocTagGenericUsesDecorator.php | 4 ++-- .../Fixture/skip_used_in_see.php.inc | 23 +++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 tests/Issues/NoNamespaced/Fixture/skip_used_in_see.php.inc diff --git a/src/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php b/src/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php index a4bfec55866..a601b72c306 100644 --- a/src/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php +++ b/src/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php @@ -455,11 +455,13 @@ public function getGenericTagClassNames(): array continue; } + // add default original value + $resolvedClasses[] = $genericTagValueNode->value; if (! str_contains($genericTagValueNode->value, '::')) { - $resolvedClasses[] = $genericTagValueNode->value; continue; } + // add resolved class name if any $resolvedClass = $genericTagValueNode->getAttribute(PhpDocAttributeKey::RESOLVED_CLASS); if ($resolvedClass === null) { $resolvedClasses[] = $genericTagValueNode->value; diff --git a/src/BetterPhpDocParser/PhpDocParser/PhpDocTagGenericUsesDecorator.php b/src/BetterPhpDocParser/PhpDocParser/PhpDocTagGenericUsesDecorator.php index 45f0444e9ee..df31fe464a9 100644 --- a/src/BetterPhpDocParser/PhpDocParser/PhpDocTagGenericUsesDecorator.php +++ b/src/BetterPhpDocParser/PhpDocParser/PhpDocTagGenericUsesDecorator.php @@ -15,7 +15,7 @@ use Rector\StaticTypeMapper\Naming\NameScopeFactory; /** - * Decorate node with fully qualified class name for generic annotations for @uses + * Decorate node with fully qualified class name for generic annotations for @uses, @used-by, and @see * e.g. @uses Direction::* * * @see https://docs.phpdoc.org/guide/references/phpdoc/tags/uses.html @@ -46,7 +46,7 @@ public function decorate(PhpDocNode $phpDocNode, PhpNode $phpNode): void return null; } - if (! in_array($node->name, ['@uses', '@used-by'], true)) { + if (! in_array($node->name, ['@uses', '@used-by', '@see'], true)) { return null; } diff --git a/tests/Issues/NoNamespaced/Fixture/skip_used_in_see.php.inc b/tests/Issues/NoNamespaced/Fixture/skip_used_in_see.php.inc new file mode 100644 index 00000000000..cd199f3649e --- /dev/null +++ b/tests/Issues/NoNamespaced/Fixture/skip_used_in_see.php.inc @@ -0,0 +1,23 @@ + $types + */ + public function __construct( + public array $types, + ) {} + + /** + * Returns true if the location is a city + * + * @see Place::isCity() + */ + public function isCity() : bool + { + return in_array('locality', $this->types, true); + } +}