Esempio n. 1
0
 /**
  * Scan a php file
  * @param FileContext $file 
  */
 public function scan(FileContext $file)
 {
     $filename = $file->getName();
     $code = file_get_contents($filename);
     try {
         // parse
         $stmts = $this->parser->parse($code);
         // traverse
         $traverser = $this->factory->createTraverser($file);
         $traverser->traverse($stmts);
     } catch (PhpParser\Error $e) {
         echo "\n\nParse Error: " . $e->getMessage() . " ({$filename})\n";
     } catch (\Exception $e) {
         echo "\n\n" . $e->getMessage() . " (in {$filename})\n";
     }
 }
Esempio n. 2
0
 /**
  * Generate file
  * @param FileContext $file
  */
 public function generateFile(FileContext $file)
 {
     // Load code and line numbers into array
     $code = $this->getContentInTuples($file->getName());
     // load scopes names, lines and issues
     $scopes = $file->getContextsNumberOfIssues();
     // get list of issues per line
     $issues = $file->getIssues(true);
     foreach ($issues as $issue) {
         $code[$issue->getLine() - 1]['issues'][] = ['type' => $issue->getTitle(), 'name' => $issue->getID()];
     }
     // render
     $view = new Mustache_Engine(['loader' => new Mustache_Loader_FilesystemLoader(__DIR__ . '/views')]);
     $relFilename = $this->convertPathToRelative($file->getName());
     $output = $view->render('file', ['currentPath' => $relFilename, 'scopes' => $scopes, 'lines' => $code, 'date' => date('r')]);
     $this->saveFile($relFilename . '.html', $output);
 }
 /**
  * @covers edsonmedina\php_testability\Contexts\FileContext::__construct
  */
 public function testConstructor()
 {
     $context = new FileContext('foo');
     $this->assertEquals('foo', $context->getName());
 }