Exemple #1
0
 private function generateSettings()
 {
     $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');
     }
     $info[] = array('Number of PHP files', $this->datastore->getHash('files'));
     $info[] = array('Number of lines of code', $this->datastore->getHash('loc'));
     $info[] = array('Number of lines of code with comments', $this->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 . ') ');
     $settings = '';
     foreach ($info as $i) {
         $settings .= "<tr><td>{$i['0']}</td><td>{$i['1']}</td></tr>";
     }
     $html = $this->getBasedPage('used_settings');
     $html = $this->injectBloc($html, 'SETTINGS', $settings);
     $this->putBasedPage('used_settings', $html);
 }
Exemple #2
0
 public static function findFiles($path, &$files, &$ignoredFiles)
 {
     $config = Config::factory();
     $ignore_dirs = $config->ignore_dirs;
     $dir = $config->project;
     // Actually finding the files
     $ignoreDirs = array();
     foreach ($ignore_dirs as $ignore) {
         if ($ignore[0] == '/') {
             $d = $config->projects_root . '/projects/' . $dir . '/code' . $ignore;
             if (!file_exists($d)) {
                 continue;
             }
             $ignoreDirs[] = $ignore . '.*';
         } else {
             $ignoreDirs[] = '.*' . $ignore . '.*';
         }
     }
     if (empty($ignoreDirs)) {
         $regex = '';
     } else {
         $regex = '#^(' . implode('|', $ignoreDirs) . ')#';
     }
     $php = new Phpexec();
     $ignoredFiles = array();
     $d = getcwd();
     if (!file_exists($path)) {
         display("No such file as " . $path . " when looking for files\n");
         $files = array();
         $ignoredFiles = array();
         return;
     }
     chdir($path);
     $files = rglob('.');
     chdir($d);
     $exts = $config->file_extensions;
     foreach ($files as $id => &$file) {
         $file = substr($file, 1);
         $ext = pathinfo($file, PATHINFO_EXTENSION);
         if (empty($ext)) {
             // it's OK.
         } elseif (!in_array($ext, $exts)) {
             // selection of extensions
             unset($files[$id]);
             $ignoredFiles[$file] = "Ignored extension ({$ext})";
         } elseif (!empty($regex) && preg_match($regex, $file)) {
             // Matching the 'ignored dir' pattern
             unset($files[$id]);
             $ignoredFiles[$file] = 'Ignored dir';
         } elseif ($php->countTokenFromFile($path . $file) < 2) {
             unset($files[$id]);
             $ignoredFiles[$file] = 'Not a PHP File';
         }
     }
 }
Exemple #3
0
 private function countLocInFile($filename)
 {
     $return = array('comments' => 0, 'whitespace' => 0, 'tokens' => 0, 'total' => 0, 'code' => 0, 'files' => 1);
     $lines = array();
     $php = new Phpexec();
     $tokens = $php->getTokenFromFile($filename);
     if (empty($tokens)) {
         display("{$filename} is empty\n");
         $return['files'] = 0;
         $return['error'] = self::EMPTYFILE;
         return $return;
     }
     // One token if it fails compilation but we don't know the error
     if (count($tokens) == 1) {
         display("{$filename} doesn't compile\n");
         $return['files'] = 0;
         $return['error'] = self::INCOMPILABLE;
         return $return;
     }
     $line = 0;
     foreach ($tokens as $token) {
         if (is_array($token)) {
             $line = $token[2];
             $tokenName = token_name($token[0]);
             // counting comments
             if ($tokenName == 'T_DOC_COMMENT') {
                 $return['comments'] += substr_count($token[1], "\n") + 1;
             } elseif ($tokenName == 'T_COMMENT') {
                 ++$return['comments'];
             } elseif ($tokenName == 'T_WHITESPACE') {
                 ++$return['whitespace'];
             } else {
                 if (isset($lines[$line])) {
                     ++$lines[$line];
                 } else {
                     $lines[$line] = 1;
                 }
                 ++$return['tokens'];
             }
         } else {
             ++$return['tokens'];
             if (!in_array($token, array('{', '}'))) {
                 if (isset($lines[$line])) {
                     ++$lines[$line];
                 } else {
                     $lines[$line] = 1;
                 }
             }
         }
     }
     if (is_array($token) && $tokenName == 'T_CLOSE_TAG') {
         --$lines[$line];
         if ($lines[$line] == 0) {
             unset($lines[$line]);
             --$line;
         }
     }
     $return['total'] = $line;
     $return['code'] = count($lines);
     $return['error'] = self::OK;
     return $return;
 }
Exemple #4
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);
 }
Exemple #5
0
 private function checkPHP($configVersion, $displayedVersion)
 {
     $phpname = 'PHP ' . $displayedVersion;
     $stats = array();
     if (!$configVersion) {
         $stats['configured'] = 'No';
     } else {
         $stats['configured'] = 'Yes (' . $configVersion . ')';
         $php = new Phpexec($displayedVersion);
         $version = $php->getVersion();
         if (strpos($version, 'not found') !== false) {
             $stats['installed'] = 'No';
         } elseif (strpos($version, 'No such file') !== false) {
             $stats['installed'] = 'No';
         } else {
             $stats['version'] = $version;
             if (substr($version, 0, 3) != $displayedVersion) {
                 $stats['version'] = $version . ' (This doesn\'t seem to be version ' . $displayedVersion . ')';
             }
             $stats['short_open_tags'] = $php->getShortTag();
             $stats['timezone'] = $php->getTimezone();
             $stats['tokenizer'] = $php->getTokenizer();
             $stats['memory_limit'] = $php->getMemory_limit();
         }
     }
     return $stats;
 }
Exemple #6
0
 private function readProjectConfig($project)
 {
     if (!file_exists($this->projects_root . '/projects/' . $project . '/config.ini')) {
         $this->projectConfig = array();
     } else {
         $this->projectConfig = parse_ini_file($this->projects_root . '/projects/' . $project . '/config.ini');
     }
     // removing empty values in the INI file
     foreach ($this->projectConfig as &$value) {
         if (is_array($value) && empty($value[0])) {
             unset($value[0]);
         }
     }
     unset($value);
     $other_php_versions = array();
     foreach (array('52', '53', '54', '55', '56', '70', '71', '72') as $version) {
         if (empty($this->configFile['php' . $version])) {
             continue;
         }
         $php = new Phpexec($version[0] . '.' . $version[1]);
         if ($php->isValid()) {
             $other_php_versions[] = $version;
         }
     }
     // check and default values
     $defaults = array('ignore_dirs' => array('/test', '/tests', '/Tests', '/Test', '/example', '/examples', '/docs', '/doc', '/tmp', '/version', '/vendor', '/js', '/lang', '/data', '/css', '/cache', '/vendor', '/assets', '/spec', '/sql'), 'other_php_versions' => $other_php_versions, 'phpversion' => PHP_VERSION, 'file_extensions' => array('php', 'php3', 'inc', 'tpl', 'phtml', 'tmpl', 'phps', 'ctp'));
     foreach ($defaults as $name => $value) {
         if (empty($this->projectConfig[$name])) {
             $this->projectConfig[$name] = $value;
         }
     }
     if (is_string($this->projectConfig['other_php_versions'])) {
         $this->projectConfig['other_php_versions'] = explode(',', $this->projectConfig['other_php_versions']);
         foreach ($this->projectConfig['other_php_versions'] as &$version) {
             $version = str_replace('.', '', trim($version));
         }
         unset($version);
     }
     if (is_string($this->projectConfig['file_extensions'])) {
         $this->projectConfig['file_extensions'] = explode(',', $this->projectConfig['file_extensions']);
         foreach ($this->projectConfig['file_extensions'] as &$ext) {
             $ext = trim($ext, '. ');
         }
         unset($ext);
     }
 }