/** * Traverse a node * * @param NodeInterface $node * @param int $recurse Max recursion level * @param int $level Recursion level */ public function traverse(NodeInterface $node, $recurse = -1, $level = 0) { if ($this->mustVisitNode($node)) { // Visit node $this->nodeVisitor->setLevel($level); $this->nodeVisitor->setShowFullPath(0 === $level); $node->accept($this->nodeVisitor); // Visit properties if ($this->propertyVisitor !== null) { foreach ($node->getProperties() as $prop) { if ($this->mustVisitProperty($prop)) { $this->propertyVisitor->setLevel($level); $prop->accept($this->propertyVisitor); } } } // Visit children foreach ($node->getNodes() as $child) { if ($recurse < 0 || $level < $recurse) { $this->traverse($child, $recurse, $level + 1); } } } }