Skip to content

How to determine if ConstFetch is used as default value of property/param #8208

Answered by samsonasik
Wirone asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, you can add Param and PropertyProperty to getNodeTypes() sorted before ConstFetch definiton:

public function getNodeTypes(): array
{
    return [Param::class, PropertyProperty::class, ConstFetch::class];
}

Then check on refactor() method early:

public function refactor(Node $node) {
    if ($node instanceof Param || $node instanceof  PropertyProperty) {
        return \PhpParser\NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
    } 

    // else process the ConstFetch that not in param or propertyproperty

Above is pseudocode, but you got the idea :)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Wirone
Comment options

Answer selected by samsonasik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants