Skip to content

Best way to remove node with traverseNodesWithCallable in 0.17.1? #8000

@timmipetit

Description

@timmipetit

Question

Rector 0.17.1 removed effectively removed removeNode. In some of our custom rules we have some code that looks like this:

 $this->traverseNodesWithCallable((array) $classMethod->stmts, function (Node $subNode) : ?Node {
    if(someConditionThatWeDecide()) {
        $this->removeNode($subNode);
    }
});

What is the best way moving forward for code like this? When changing the traverseNodesWithCallable into a foreach($node->stmts as $key => $subNode) we obviously get less subnodes to process and have to add some extra code to get the nodes that we want. Is this the correct way?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions