{{ message }}
[BetterPhpDocParser] Keep import referenced by @see/@uses tag with a trailing description#8039
Merged
Merged
Conversation
@see/@uses tag with a trailing description
Contributor
Author
samsonasik
reviewed
Jun 16, 2026
…trailing description When `removeUnusedImports()` is enabled, UnusedImportRemovingPostRector collects the class names used inside doc blocks through PhpDocInfo::getGenericTagClassNames(). For generic tags such as @see, @uses and @link it only registered the full tag value. A tag like `@see Foo some description` therefore produced the single candidate "Foo some description", which never matches the imported short name "Foo". As a result the `use` import for Foo was considered unused and removed, leaving an unresolved reference (or, for a class in another namespace, one that silently resolves to the wrong class). Per the phpDocumentor syntax `@see [FQSEN] [<description>]`, the class reference is the leading token of the value. Register that leading token in addition to the full value, so the import is correctly kept when a description follows the class name.
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

When
removeUnusedImports()is enabled, UnusedImportRemovingPostRector collects the class names used inside doc blocks through PhpDocInfo::getGenericTagClassNames(). For generic tags such as@see,@usesand@linkit only registered the full tag value.A tag like
@see Foo some descriptiontherefore produced the single candidate "Foo some description", which never matches the imported short name "Foo". As a result theuseimport for Foo was considered unused and removed, leaving an unresolved reference (or, for a class in another namespace, one that silently resolves to the wrong class).Per the phpDocumentor syntax
@see [FQSEN] [<description>], the class reference is the leading token of the value. Register that leading token in addition to the full value, so the import is correctly kept when a description follows the class name.