Im using https://github.com/nikic/PHP-Parser. What is a good strategy when wanting to INSERT a node in the AST? With the traverser I can UPDATE and DELETE nodes easily using a NodeTraverser
class. But how can I "INSERT before" or "INSERT after" a node?
Example: When traversing an AST namespace I want to INSERT a Use
statement just before the first non-use statement.
I started working with beforeTraverse
and afterTraverse
to find indexes of arrays but it seems overly complicated. Any ideas?