Repository navigation
Write class names added by fixes relative to namespace and uses - #6924
Merged
Merged
Conversation
ondrejmirtes
force-pushed
the
fixer-new-class-names
branch
4 times, most recently
from
November 3, 2026 11:05
f7d29eb to
7791cea
Compare
NewClassNamesVisitor runs after every fix and writes the fully qualified class names a fix added, in PHP code and in PHPDocs, relative to the current namespace and existing use statements. With fixer.importNames (on by default) it adds a use statement for a name from another namespace unless its short name already means something in the file. fixer.preferSelf writes the current class as self. The migrate:neon2attributes command now builds fully qualified names and lets the visitor import them, replacing ImportScope. Amp-Thread-ID: https://ampcode.com/threads/T-01a179f2-995f-7745-8d8c-4c174ba5c0ce
ondrejmirtes
force-pushed
the
fixer-new-class-names
branch
from
November 3, 2026 11:11
7791cea to
ec0010d
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 now write the class names they add the same way a person would, in PHP code and in PHPDocs.
NewClassNamesVisitorruns after all fixes in a file are applied. For each fully qualified class name the fix added (names already in the file are left as written):selffor the current class, iffixer.preferSelfis enabled (not in attributes,extends,implements, or traituse),useor to the current namespace,usestatement, iffixer.importNamesis enabled and the short name does not already mean something in the file (an existing use alias, a declared class, a relative name in code or PHPDoc),New
usestatements are inserted alphabetically among the existing ones, beforeuse function/use const, or afterdeclarewith a blank line when it's the first one.New parameters:
Global-namespace classes are not imported, so
#[Override]stays#[\Override]unlessuse Override;is already there.migrate:neon2attributesnow builds fully qualified names and lets the visitor import them;ImportScopeandcreateName()are removed. Its existing tests pass unchanged.Tests:
AddNamesRuletest rule adding native and PHPDoc types (default config, andimportNames: false+preferSelf: true), plus#[Override]fixes with an existinguse Overrideand in the global namespace.