Exemple #1
0
 /** @dataProvider provideTestParseAndDump */
 public function testParseAndDump($code, $expectedDump)
 {
     $astTraverser = new PhpParser\NodeTraverser();
     $astTraverser->addVisitor(new PhpParser\NodeVisitor\NameResolver());
     $parser = new Parser(new PhpParser\Parser(new PhpParser\Lexer()), $astTraverser);
     $dumper = new Dumper();
     $block = $parser->parse($code, 'foo.php');
     $this->assertEquals($this->canonicalize($expectedDump), $this->canonicalize($dumper->dump($block)));
 }
Exemple #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->loadRules();
     $parser = new CFGParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7));
     $graphs = $this->getGraphsFromFiles($input->getArgument('files'), $input->getOption("exclude"), $parser);
     if ($input->getOption('dump')) {
         $dumper = new Dumper();
         foreach ($graphs as $key => $graph) {
             echo "Graph #{$key}\n";
             echo $dumper->dump($graph);
             echo "\n";
         }
     }
     $errors = $this->analyzeGraphs($graphs);
     if ($errors) {
         echo "\nErrors found:\n";
         foreach ($errors as $error) {
             $this->emitError($error[0], $error[1]);
         }
     }
 }