/** 
  * Scans (recursively) the path and runs the analyser for each file
  * @param ContextInterface $parent 
  */
 public function iterate(ContextInterface $parent)
 {
     $path = $parent->getName();
     foreach (new \DirectoryIterator($path) as $fileInfo) {
         if ($fileInfo->isDot()) {
             continue;
         }
         $fullPath = $path . DIRECTORY_SEPARATOR . $fileInfo->getFilename();
         if ($fileInfo->isDir() && !$this->isDirExcluded($fileInfo->getFilename())) {
             $dir = new DirectoryContext($fullPath);
             $this->iterate($dir);
             // no need to keep directories
             // with no mathing files
             if ($dir->hasChildren()) {
                 $parent->addChild($dir);
             }
         } elseif ($this->hasPhpExtension($fileInfo->getFilename())) {
             $file = new FileContext($fullPath);
             if ($this->verbose) {
                 echo $path . DIRECTORY_SEPARATOR . $fileInfo->getFilename() . "... ";
             }
             $this->analyser->scan($file);
             if ($this->verbose) {
                 echo "OK\n";
             } else {
                 echo ".";
             }
             $parent->addChild($file);
             $this->processedFilesCount++;
         }
     }
 }
 /**
  * Generate index file
  * @param ContextInterface $path (DirectoryInterface or RootInterface)
  */
 public function generateIndexFile(ContextInterface $path)
 {
     // list directory
     $files = [];
     $dirs = [];
     $dir_testable = 0;
     $dir_total = 0;
     foreach ($path->getChildren() as $child) {
         $filename = $child->getName();
         $numbers = $this->getTotalTestableProcedures($child);
         $percent = $numbers['total'] > 0 ? $numbers['testable'] / $numbers['total'] : 1;
         $node = ['name' => basename($filename), 'total' => $numbers['total'], 'testable' => $numbers['testable'], 'percent' => number_format($percent * 100, 2), 'label' => $numbers['total'] ? $this->getCssClass($percent) : ''];
         $dir_testable += $numbers['testable'];
         $dir_total += $numbers['total'];
         if ($child instanceof DirectoryContext) {
             $dirs[] = $node;
         } elseif ($child instanceof FileContext) {
             $files[] = $node;
         }
     }
     $dir_percent = $dir_total > 0 ? $dir_testable / $dir_total : 1;
     // render
     $view = new Mustache_Engine(['loader' => new Mustache_Loader_FilesystemLoader(__DIR__ . '/views')]);
     $relPath = $this->convertPathToRelative($path->getName());
     $output = $view->render('dir', ['currentPath' => $relPath, 'files' => $files, 'dirs' => $dirs, 'date' => date('r'), 'total_percent' => number_format($dir_percent * 100, 2), 'total_testable' => $dir_testable, 'total_total' => $dir_total, 'isBaseDir' => $this->baseDir === $path->getName()]);
     $this->saveFile($relPath . '/index.html', $output);
 }
 /**
  * @param ContextInterface $report
  * @param string $reportDir Where to generate the report 
  */
 public function __construct(ContextInterface $report, $reportDir)
 {
     $this->baseDir = $report->getName();
     $this->reportDir = $reportDir;
     $this->report = $report;
 }