fix(CommandHelpToAttributeRector): support concatenated string in setHelp()#932
Merged
TomasVotruba merged 1 commit intoMay 7, 2026
Merged
Conversation
…Help() Previously the rule only handled plain String_ literals. When setHelp() received a Concat expression (e.g. "line one\n" . "line two") it silently dropped the call without migrating the text to #[AsCommand(help: ...)], leaving the help text permanently lost. Introduce resolveStringExpr() that recursively folds a Concat tree of String_ literals into a single string value. Non-literal sub-expressions (variables, function calls, …) cause the method to return null, which now also prevents the setHelp() removal — fixing the silent data-loss bug.
Member
|
Looks good, thank you 👍 |
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.
Previously the rule only handled plain String_ literals. When
setHelp()received a Concat expression (e.g. "line one\n" . "line two") it silently dropped the call without migrating the text to#[AsCommand(help: ...)], leaving the help text permanently lost.Introduce
resolveStringExpr()that recursively folds a Concat tree of String_ literals into a single string value. Non-literal sub-expressions (variables, function calls, …) cause the method to return null, which now also prevents thesetHelp()removal — fixing the silent data-loss bug.Problem
CommandHelpToAttributeRectoronly handles a plainString_literal as the argument tosetHelp(). When the argument is a concatenated string (a tree ofConcatnodes), the rule exhibits two bugs:setHelp()is removed from the method chain (viareturn $node->varin the traversal callback) even though$helpStringis never set, so the help text is permanently discarded.$helpStringstaysnull,refactor()returnsnulland nothing is added to#[AsCommand(help: ...)].Example that triggered the bug:
Fix
resolveStringExpr(Expr): ?string— recursively folds aConcattree ofString_literals into a single string value. Returnsnullfor any non-literal sub-expression (variables, function calls, …).instanceof String_check with a call toresolveStringExpr().return $node->var(which removessetHelp()) now only executes when$resolvedValue !== null— so non-resolvable expressions are left untouched instead of being silently dropped.Test
Added
add_help_concatenated_string.php.incfixture covering asetHelp()call with a multi-line concatenated string alongside another chained method call (addOption).