Esempio n. 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";
         }
     }
 }
Esempio n. 2
0
 private static function saveTokenCounts()
 {
     $config = Config::factory();
     $datastore = new Datastore($config);
     $datastore->addRow('tokenCounts', static::$tokenCounts);
 }
Esempio n. 3
0
 protected function AuditConfiguration()
 {
     $css = new \Stdclass();
     $css->displayTitles = false;
     $css->titles = array(0, 1);
     $css->readOrder = $css->titles;
     $info = array(array('Code name', $this->config->project_name));
     if (!empty($this->config->project_description)) {
         $info[] = array('Code description', $this->config->project_description);
     }
     if (!empty($this->config->project_packagist)) {
         $info[] = array('Packagist', '<a href="https://packagist.org/packages/' . $this->config->project_packagist . '">' . $this->config->project_packagist . '</a>');
     }
     if (!empty($this->config->project_url)) {
         $info[] = array('Home page', '<a href="' . $this->config->project_url . '">' . $this->config->project_url . '</a>');
     }
     if (file_exists($this->config->projects_root . '/projects/' . $this->config->project . '/code/.git/config')) {
         $gitConfig = file_get_contents($this->config->projects_root . '/projects/' . $this->config->project . '/code/.git/config');
         preg_match('#url = (\\S+)\\s#is', $gitConfig, $r);
         $info[] = array('Git URL', $r[1]);
         $res = shell_exec('cd ' . $this->config->projects_root . '/projects/' . $this->config->project . '/code/; git branch');
         $info[] = array('Git branch', trim($res));
         $res = shell_exec('cd ' . $this->config->projects_root . '/projects/' . $this->config->project . '/code/; git rev-parse HEAD');
         $info[] = array('Git commit', trim($res));
     } else {
         $info[] = array('Repository URL', 'Downloaded archive');
     }
     $datastore = new Datastore($this->config);
     $info[] = array('Number of PHP files', $datastore->getHash('files'));
     $info[] = array('Number of lines of code', $datastore->getHash('loc'));
     $info[] = array('Number of lines of code with comments', $datastore->getHash('locTotal'));
     $info[] = array('Report production date', date('r', strtotime('now')));
     $php = new Phpexec($this->config->phpversion);
     $info[] = array('PHP used', $php->getActualVersion() . ' (version ' . $this->config->phpversion . ' configured)');
     $info[] = array('Ignored files/folders', implode(', ', $this->config->ignore_dirs));
     $info[] = array('Exakat version', Exakat::VERSION . ' ( Build ' . Exakat::BUILD . ') ');
     return $this->formatSimpleTable($info, $css);
 }