Skip to content

Keep the full name of a class a fix writes into a use statement - #6929

Open
SanderMuller wants to merge 1 commit into
phpstan:2.3.xfrom
SanderMuller:fix-names-in-use-statements
Open

SanderMuller wants to merge 1 commit into
phpstan:2.3.xfrom
SanderMuller:fix-names-in-use-statements

Conversation

@SanderMuller

Copy link
Copy Markdown
Contributor

A fix that puts a FullyQualified name into a use statement gets only the short name. When a rule replaces the name in use RenameUseOther\Foo; with new FullyQualified('RenameUseOther\Bar'), --fix writes use Bar;. With an alias it writes use Lorem as Lorem;.

NewClassNamesVisitor treats the name like any other class name that a fix added. It writes the name relative to the alias that the same use statement creates. Now a new FullyQualified name in a use statement becomes a plain Name, so the statement keeps the full name. If the visitor only skipped the name, the statement would get a leading backslash.

I hit this in a rule that renames a class and every reference to it.

🤖 Generated with Claude Code

NewClassNamesVisitor wrote a fully qualified name that a fix put into
a use statement relative to the alias of that same statement. A fix
that replaced `use Foo\Old;` with `Foo\New` gave `use New;`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant