public function shouldTraverse(NodeTraversal $t, \PHPParser_Node $node, \PHPParser_Node $parent = null) { $graphNode = $t->getControlFlowGraph()->getNode($node); if (null !== $graphNode && GraphReachability::UNREACHABLE === $graphNode->getAttribute(GraphReachability::ATTR_REACHABILITY)) { // Only report error when there are some line number informations. // There are synthetic nodes with no line number informations, nodes // introduced by other passes (although not likely since this pass should // be executed early) or some PHPParser bug. if (-1 !== $node->getLine()) { $this->file->addComment($node->getLine(), Comment::warning('usage.unreachable_code', '``%unreachable_code%`` is not reachable.', array('unreachable_code' => $this->prettyPrinter->prettyPrint(array($node))))); // From now on, we are going to assume the user fixed the error and not // give more warnings related to code sections reachable from this node. $r = new GraphReachability($t->getControlFlowGraph()); $r->recompute($node); // Saves time by not traversing children. return false; } } return true; }
private function compute(\PHPParser_Node $ast) { $r = new GraphReachability($graph = $this->getCfg($ast)); $r->compute($ast); }