コード例 #1
0
 public function test()
 {
     $class = get_class($this);
     $class = substr($class, 41);
     $file_name = $class . '.inc';
     $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
     $traverser = new NodeTraverser();
     // add your visitor
     $collector = new Collector();
     $traverser->addVisitor(new NodeVisitor($collector, new Config()));
     try {
         $code = file_get_contents(__DIR__ . '/../tests/' . $file_name);
         // parse
         $stmts = $parser->parse($code);
         // traverse
         $traverser->traverse($stmts);
         $found = $collector->get();
         foreach ($found as &$item) {
             unset($item['node']);
         }
         $this->assertEquals($this->expectations(), $found);
     } catch (Error $e) {
         echo 'Parse Error: ', $e->getMessage();
     }
 }
コード例 #2
0
 protected function scan_file($file_name)
 {
     try {
         $this->logger->info('Scanning ' . $file_name);
         $code = file_get_contents($file_name);
         $this->traverser->traverse($this->parser->parse($code));
     } catch (Error $e) {
         $this->logger->error('Parse Error: ' . $e->getMessage());
     }
     foreach ($this->collector->get() as $result) {
         $this->logger->notice($result['function'] . '(): ' . $result['item']);
     }
     $this->collector->reset();
 }