How to replace an ArrayDimFetch
with a string
#7059
Unanswered
AngelinCalu
asked this question in
Q&A
Replies: 2 comments 7 replies
-
Hi, instead of replacing one item many encapsed strings, it's better to hook on the parent and replace that one. Could you share the rule? |
Beta Was this translation helpful? Give feedback.
3 replies
-
That's because by replacing node, the original formatting might be loss. The best in the long-term is to add coding standard that will handle the code spacing for you. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to create a new custom rule which is supposed to replace all occurrences of
$var['key']
withresolved_key
string inside Encapsed strings.The snippet above will produce:
$test = "string before {'resolved_key'} string after";
instead of:
$test = "string before resolved_key string after";
Do I need to check if the parent node is
instanceof \PhpParser\Node\Scalar\Encapsed
and try to alter the sibling nodes or is there some better way I'm not aware of?Beta Was this translation helpful? Give feedback.
All reactions