[BetterPhpDocParser] Keep import used only in an annotation array key - #8429
Merged
Conversation
… like @Orm\DiscriminatorMap({ SomeEnum::TOTP = ... }) The ArrayItemClassNameDecorator only resolved the class from the value side of an array item, so a class referenced solely in the key of a Doctrine annotation map was not counted as used. With removeUnusedImports() enabled the import was then wrongly removed. Claude-Session: https://claude.ai/code/session_01DnwXQN191Le8TVieRZnWv6
TomasVotruba
force-pushed
the
fix-annotation-array-key-const-import
branch
from
September 2, 2026 09:03
e7ecd0f to
a9a90cd
Compare
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.
Fixes wrong removal of a
useimport that is referenced only in the key side of a Doctrine annotation array, e.g.@ORM\DiscriminatorMap({ SomeEnum::TOTP = ... }).Reported via demo: https://getrector.com/demo/a835e33e-668f-47f5-8cf8-604988f8b0de
Problem
ArrayItemClassNameDecoratorresolved the class name only from the array item value ($node->value). A class used solely in the key (SomeEnum::TOTP) got noRESOLVED_CLASS, sogetArrayItemNodeClassNames()never reported it. WithremoveUnusedImports()on,UnusedImportRemovingPostRectorthen treated the import as unused and removed it.Before:
Fix
RESOLVED_KEY_CLASSattribute.getArrayItemNodeClassNames()now collects both value and key resolved classes.Covered by a skip fixture in
tests/Issues/NamespacedUseAutoImport.