Ejemplo n.º 1
0
 /**
 ----------------------------------------------------------------------+
 * @desc 	Analyse directory
 ----------------------------------------------------------------------+
 */
 protected function lint_directory()
 {
     $ext = $this->config->check('extensions');
     if (empty($ext)) {
         $ext = 'php';
     }
     $ignore = $this->config->check('ignore');
     $this->msg("Gathering file info...\n");
     $files = empty($ignore) ? Path::find($this->target, "/^.*?\\.({$ext})\$/u") : Path::find($this->target, "/^.*?\\.({$ext})\$/u", $ignore);
     if ($this->config->check(OPT_HARVEST_DOCS)) {
         $this->msg("Harvesting mode on ...\n");
     }
     $this->penalty = 0;
     $numfiles = count($files);
     $reports = array();
     $penaltys = array();
     $nodes = array();
     foreach ($files as $_) {
         $this->msg("Linting file: {$_}\n");
         if ($this->config->check(OPT_DEBUG_TIME_EXTRA)) {
             $time = microtime(true);
         }
         $linter = new Linter($_, $this->config);
         $report = $linter->lint();
         $penalty = $linter->penalty();
         $stats = array($_, $linter->score());
         if ($this->config->check(OPT_REPORT)) {
             if ($_[0] !== '/') {
                 $href = preg_match('/^\\.\\//u', $_) ? $_ : "./{$_}";
             } else {
                 $href = $_;
             }
             $penaltys[$href] = $penalty;
             $reports[$href] = $report;
         }
         if ($this->config->check(OPT_HARVEST_DOCS)) {
             $penaltys[$_] = $penalty;
             $nodes[] = $linter->nodes();
         }
         $this->penalty += $penalty;
         $this->msg($this->reporter->score($penalty));
         if ($this->config->check(OPT_DEBUG_TIME_EXTRA)) {
             $x = microtime(true) - $time;
             $stats[] = $x;
             $this->msg("Time for file: {$x} seconds\n");
         }
         $this->stats[] = $stats;
     }
     if ($this->config->check(OPT_HARVEST_DOCS)) {
         $reporter = new Report\Harvest($this->config);
         $reporter->create($nodes, $penaltys, $this->target);
     }
     $this->reporter->create($reports, $penaltys, $this->target);
     $cnt = count($this->stats);
     $this->msg("{$cnt} files, ", 0);
     $this->msg($this->reporter->average($this->penalty, $numfiles), 0);
     $arr = array();
     foreach ($this->stats as $_) {
         $arr[] = $_[1];
     }
     array_multisort($this->stats, SORT_NUMERIC, $arr);
     $this->msg("Worst: {$this->stats[0][0]} with {$this->stats[0][1]}\n", 0);
     if ($this->config->check(OPT_DEBUG_TIME_EXTRA)) {
         $arr = array();
         foreach ($this->stats as $_) {
             $arr[] = $_[2];
         }
         $avg = array_sum($arr) / $cnt;
         echo "Avarage time per file: {$avg} seconds\n";
     }
 }