getCol() публичный Метод

public getCol ( $table, $col )
Пример #1
0
 public function run()
 {
     $loc = array('files' => 0, 'total' => 0, 'tokens' => 0, 'comments' => 0, 'code' => 0);
     $project = $this->config->project;
     if ($project != 'default') {
         $projectPath = $this->config->projects_root . '/projects/' . $project;
         if (!file_exists($projectPath)) {
             throw new NoSuchProject($this->config->project);
         }
         if (!file_exists($projectPath . '/datastore.sqlite')) {
             throw new NoDatastore($this->config->project);
         }
         $datastore = new Datastore($this->config);
         $files = $datastore->getCol('files', 'file');
         foreach ($files as $file) {
             $counts = $this->countLocInFile($this->config->projects_root . '/projects/' . $project . '/code' . $file);
             array_add($loc, $counts);
             if ($counts['error'] != self::OK) {
                 $datastore->deleteRow('files', array('file' => $file));
                 $datastore->addRow('ignoredFiles', array(array('file' => $file, 'reason' => $counts['error'])));
                 display("Finally ignoring {$file}\n");
             }
         }
         $this->datastore->addRow('hash', array(array('key' => 'loc', 'value' => $loc['code']), array('key' => 'locTotal', 'value' => $loc['total']), array('key' => 'files', 'value' => $loc['files']), array('key' => 'tokens', 'value' => $loc['tokens'])));
     } elseif (!empty($this->config->dirname)) {
         $dirPath = $this->config->dirname;
         $ignoreDirs = array();
         $ignoreName = array();
         foreach ($this->config->ignore_dirs as $ignore) {
             if ($ignore[0] == '/') {
                 $d = $dirPath . $ignore;
                 if (file_exists($d)) {
                     $ignoreDirs[] = $d;
                 }
             } else {
                 $ignoreName[] = $ignore;
             }
         }
         $files = $this->readRecursiveDir($dirPath, $ignoreName, $ignoreDirs);
         foreach ($files as $file) {
             array_add($loc, $this->countLocInFile($file));
         }
     } elseif (!empty($this->config->filename)) {
         $loc = $this->countLocInFile($this->config->filename);
     } else {
         print "Usage : php exakat phploc <-p project> <-d dirname> <-f filename>\n";
         return;
     }
     if ($this->config->json) {
         print json_encode($loc);
     } elseif ($this->config->verbose) {
         foreach ($loc as $k => $v) {
             print substr("{$k}        ", 0, 8) . " : {$v}\n";
         }
     }
 }