Repository navigation
Commit 74b5d79
committed
[BetterPhpDocParser] Keep import referenced by @see/@uses tag with a 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.1 parent 9e4dc59 commit 74b5d79
2 files changed
Lines changed: 19 additions & 0 deletions
File tree
- src/BetterPhpDocParser/PhpDocInfo
- tests/Issues/NamespacedUse/Fixture
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
461 | 461 | | |
462 | 462 | | |
463 | 463 | | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
464 | 471 | | |
465 | 472 | | |
466 | 473 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
0 commit comments