getTraverser() public static method

public static getTraverser ( ) : NodeTraverser
return PhpParser\NodeTraverser
コード例 #1
0
 /**
  * Add final anonymous classes to the statements
  *
  * @param array $nodes
  * @return array
  */
 public function afterTraverse(array $nodes)
 {
     // Nothing to do when there are no anonymous classes
     if (NodeStateStack::getInstance()->count('anonClasses') == 0) {
         return $nodes;
     }
     // We must transpile anonymous classes first, as we haven't done this yet
     $traverser = Transpile::getTraverser();
     $anonClassStmts = $traverser->traverse(NodeStateStack::getInstance()->get('anonClasses'));
     // Find hook point for anonymous classes, which must be after declare, namespaces and use-statements, and can
     // before anything else. This might cause issues when anonymous classes implement interfaces that are defined
     // later on.
     $idx = $this->getAnonymousClassHookIndex($nodes);
     // Array_merge the anonymous class statements on the correct position
     $preStmts = array_slice($nodes, 0, $idx);
     $postStmts = array_slice($nodes, $idx);
     $nodes = array_merge($preStmts, $anonClassStmts, $postStmts);
     return $nodes;
 }