public function enterScope(NodeTraversal $t)
 {
     $cfg = $t->getControlFlowGraph();
     $scope = $t->getScope();
     $mayBeAnalysis = new MayBeReachingUseAnalysis($cfg, $scope);
     $mayBeAnalysis->analyze();
     $mustBeAnalysis = new MustBeReachingDefAnalysis($cfg, $scope);
     $mustBeAnalysis->setLogger($this->logger);
     $mustBeAnalysis->analyze();
 }
 protected function setUp()
 {
     $this->op = \Scrutinizer\PhpAnalyzer\DataFlow\VariableReachability\MustBeReachingDefAnalysis::createJoinOperation();
     $this->scope = new \Scrutinizer\PhpAnalyzer\PhpParser\Scope\Scope($this->getMock('PHPParser_Node'));
     $this->var = new \Scrutinizer\PhpAnalyzer\PhpParser\Scope\Variable('x', null, $this->scope);
     $this->a = new DefinitionLattice();
     $this->b = new DefinitionLattice();
 }
 private function computeDefUse($code)
 {
     $code = sprintf('<?php function foo($param1, $param2) { %s }', $code);
     $ast = ParseUtils::parse($code);
     $scope = (new SyntacticScopeCreator())->createScope($ast);
     $cfa = new ControlFlowAnalysis();
     $cfa->process($ast);
     $cfg = $cfa->getGraph();
     $this->analysis = new MustBeReachingDefAnalysis($cfg, $scope);
     $this->analysis->analyze();
     $this->def = $this->use = null;
     NodeTraversal::traverseWithCallback($ast, new PreOrderCallback(function (NodeTraversal $t, \PHPParser_Node $node) {
         if (!$node instanceof \PHPParser_Node_Stmt_Label) {
             return;
         }
         if ('D' === $node->name) {
             $this->def = $node->getAttribute('next');
         } else {
             if ('U' === $node->name) {
                 $this->use = $node->getAttribute('next');
             } else {
                 if (0 === strpos($node->name, 'DP_')) {
                     $className = 'PHPParser_Node_' . substr($node->name, 3);
                     $parent = $node;
                     while (null !== ($parent = $parent->getAttribute('parent'))) {
                         if ($parent instanceof $className) {
                             $this->def = $parent;
                             return;
                         }
                     }
                     throw new \RuntimeException(sprintf('Did not find any parent of class "%s".', $className));
                 }
             }
         }
     }));
     $this->assertNotNull($this->def, 'Did not find "D" (definition) label in the code.');
     $this->assertNotNull($this->use, 'Did not find "U" (usage) label in the code.');
 }