Repository navigation
Skip writing new class names when no fix added one - #6934
Open
SanderMuller wants to merge 1 commit into
Open
SanderMuller wants to merge 1 commit into
SanderMuller wants to merge 1 commit into
Conversation
RuleErrorTransformer ran NameResolver and NewClassNamesVisitor over the whole file for every fixable error. NewClassNamesVisitor also collects the names the file already uses, twice in a file with a namespace, and parses every PHPDoc in the file for that. A fix that adds no class name does not need any of it. ReplacingNodeVisitor now keeps the nodes that the fixes returned. The traversal runs only when one of them contains a fully qualified name without an original node, or a PHPDoc that differs from the original. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Since 95d9e8b,
RuleErrorTransformerrunsNameResolverandNewClassNamesVisitorover the whole file for every fixable error. The visitor also collects the names that the file already uses, which walks the file again and parses every PHPDoc in it. In a file with a namespace, it does this twice. A fix that adds no class name needs none of this work.ReplacingNodeVisitornow keeps the nodes that the fixes returned. The traversal runs only when these nodes contain a new fully qualified name or a changed PHPDoc.The
bug-14996benchmark has one fix per method, and none of them adds a name. It failed on every 2.3.x push since 95d9e8b, at +35% to +84%. Before that commit it also failed now and then, at +20% to +33%, so this change does not make the job always green.phpbench mode for
bug-14996.php, 4 interleaved rounds, PHP 8.5, macOS arm64:Tests:
NewClassNamesVisitorTestchecks the new check on its own. Each case fails when its branch of the check is removed.AddNamesRulegets an@add-doc-nametag that changes only the PHPDoc. Without it, every fix in the tests also added a name in PHP code, so no test covered the PHPDoc branch through the transformer.This PR and #6929 both change
NewClassNamesVisitor. They merge without conflicts, and theFixabletests pass on the merged result.Fixes that add a class name still run the full traversal for each error. A follow-up can collect the names that the file uses only when a name needs a new
usestatement.🤖 Generated with Claude Code