Exemple #1
0
 /**
  * Retrieves the parent directory all files have in common.
  *
  * @return String
  */
 public function getCommonPathPrefix()
 {
     return CbIOHelper::getCommonPathPrefix(array_keys($this->_files));
 }
Exemple #2
0
 /**
  * Convert a list of files to a html fragment for jstree.
  *
  * @param Array $fileList       The files, format: array('name' => CbFile).
  * @param String $hrefPrefix    The prefix to put before all href= tags.
  *
  * @return String           The html fragment.
  */
 protected function _getTreeListHtml(array $fileList, $hrefPrefix = '')
 {
     /*
      * In this method, all directories have a trailing DIRECTORY_SEPARATOR.
      * This is important so that $curDir doesn't become empty if we go
      * up to the root directory ('/' on linux)
      */
     $curDir = CbIOHelper::getCommonPathPrefix(array_keys($fileList)) . DIRECTORY_SEPARATOR;
     $preLen = strlen($curDir);
     $ret = '<ul>';
     foreach ($fileList as $name => $file) {
         $dir = dirname($name) . DIRECTORY_SEPARATOR;
         // Go back until the file is somewhere below curDir
         while (strpos($dir, $curDir) !== 0) {
             // chop off one subdir from $curDir
             $curDir = substr($curDir, 0, strrpos($curDir, DIRECTORY_SEPARATOR, -2) + 1);
             $ret .= '</ul></li>';
         }
         if ($dir !== $curDir) {
             // File is in a subdir of current directory
             // relDir has no leading or trailing slash.
             $relDir = substr($dir, strlen($curDir), -1);
             $relDirs = explode(DIRECTORY_SEPARATOR, $relDir);
             foreach ($relDirs as $dirName) {
                 $ret .= "<li><a class='treeDir'>{$dirName}</a><ul>";
             }
             $curDir = $dir;
         }
         $shortName = substr($name, $preLen);
         $fileName = basename($name);
         $count = '';
         if ($file->getErrorCount() != 0 || $file->getWarningCount() != 0) {
             $count .= '(<span class="errorCount">';
             $count .= $file->getErrorCount();
             $count .= '</span>|<span class="warningCount">';
             $count .= $file->getWarningCount();
             $count .= '</span>)';
         }
         $ret .= '<li class="php" ><a class="fileLink" href="';
         $ret .= $hrefPrefix . $shortName . '.html">';
         $ret .= "{$fileName} {$count}</a></li>";
     }
     $ret .= '</ul>';
     return $ret;
 }
 /**
  * Main execute function for PHP_CodeBrowser.
  *
  * Following steps are resolved:
  * 1. Clean-up output directory
  * 2. Merge xml log files
  * 3. Generate cbXML file via errorlist from plugins
  * 4. Save the cbErrorList as XML file
  * 5. Generate HTML output from cbXML
  * 6. Copy ressources (css, js, images) from template directory to output
  *
  * @return void
  */
 public function run()
 {
     // clear and create output directory
     if (is_dir($this->_htmlOutputDir)) {
         $this->_ioHelper->deleteDirectory($this->_htmlOutputDir);
     } else {
         if (is_file($this->_htmlOutputDir)) {
             $this->_ioHelper->deleteFile($this->_htmlOutputDir);
         }
     }
     $this->_ioHelper->createDirectory($this->_htmlOutputDir);
     // init needed classes
     $cbViewReview = new CbViewReview(PHPCB_TEMPLATE_DIR, $this->_htmlOutputDir, $this->_ioHelper, $this->_phpSuffixes);
     $sourceHandler = new CbSourceHandler($this->_debugLog);
     if (isset($this->_logDir)) {
         $cbIssueXml = new CbIssueXml();
         // merge xml files
         $cbIssueXml->addDirectory($this->_logDir);
         // conversion of XML file cc to cb format
         foreach ($this->_registeredPlugins as $className) {
             if (array_key_exists($className, $this->_pluginOptions)) {
                 $plugin = new $className($cbIssueXml, $this->_pluginOptions[$className]);
             } else {
                 $plugin = new $className($cbIssueXml);
             }
             $sourceHandler->addPlugin($plugin);
         }
     }
     if (isset($this->_projectSource)) {
         foreach ($this->_projectSource as $source) {
             if (is_dir($source)) {
                 $factory = new File_Iterator_Factory();
                 $suffixes = array_merge($this->_phpSuffixes, array('php', 'js', 'css', 'html'));
                 $sourceHandler->addSourceFiles($factory->getFileIterator($source, $suffixes));
             } else {
                 $sourceHandler->addSourceFile($source);
             }
         }
     }
     array_walk($this->_excludeExpressions, array($sourceHandler, 'excludeMatchingPCRE'));
     array_walk($this->_excludePatterns, array($sourceHandler, 'excludeMatchingPattern'));
     $files = $sourceHandler->getFiles();
     if (!$files) {
         $cbViewReview->copyNoErrorsIndex();
     } else {
         // Get the path prefix all files have in common
         $commonPathPrefix = $sourceHandler->getCommonPathPrefix();
         $error_reporting = ini_get('error_reporting');
         // Disable E_Strict, Text_Highlighter might throw up
         ini_set('error_reporting', $error_reporting & ~E_STRICT);
         foreach ($files as $file) {
             $cbViewReview->generate($file->getIssues(), $file->name(), $commonPathPrefix, $this->_excludeOK);
         }
         ini_set('error_reporting', $error_reporting);
         // Copy needed ressources (eg js libraries) to output directory
         $cbViewReview->copyRessourceFolders();
         $cbViewReview->generateIndex($files, $this->_excludeOK);
     }
 }
 /**
  * Convert a list of files to a html fragment for jstree.
  *
  * @param Array $fileList       The files, format: array('name' => CbFile).
  * @param String $hrefPrefix    The prefix to put before all href= tags.
  *
  * @return String           The html fragment.
  */
 protected function _getTreeListHtml(array $fileList, $hrefPrefix = '')
 {
     /*
      * In this method, all directories have a trailing DIRECTORY_SEPARATOR.
      * This is important so that $curDir doesn't become empty if we go
      * up to the root directory ('/' on linux)
      */
     $curDir = CbIOHelper::getCommonPathPrefix(array_keys($fileList));
     $preLen = strlen($curDir);
     $indentStep = 4;
     $indent = $indentStep;
     $ret = '<ul>' . PHP_EOL;
     foreach ($fileList as $name => $file) {
         $dir = dirname($name) . DIRECTORY_SEPARATOR;
         // Go back until the file is somewhere below curDir
         while (strpos($dir, $curDir) !== 0) {
             // chop off one subdir from $curDir
             $curDir = substr($curDir, 0, strrpos($curDir, DIRECTORY_SEPARATOR, -2) + 1);
             $ret .= str_pad(' ', $indent);
             $ret .= '</ul>' . PHP_EOL;
             $indent -= $indentStep;
             $ret .= str_pad(' ', $indent);
             $ret .= '</li>' . PHP_EOL;
         }
         if ($dir !== $curDir) {
             // File is in a subdir of current directory
             // relDir has no leading or trailing slash.
             $relDir = substr($dir, strlen($curDir), -1);
             $relDirs = explode(DIRECTORY_SEPARATOR, $relDir);
             foreach ($relDirs as $dirName) {
                 $curDir .= $dirName . DIRECTORY_SEPARATOR;
                 // Check how many errors/warnings are in this dir.
                 //TODO: Optimize this. Counts get recalculated for subdirs.
                 $errors = 0;
                 $warnings = 0;
                 foreach (array_keys($fileList) as $fName) {
                     if (strncmp($fName, $curDir, strlen($curDir)) === 0) {
                         $errors += $fileList[$fName]->getErrorCount();
                         $warnings += $fileList[$fName]->getWarningCount();
                     }
                 }
                 $count = '';
                 if ($errors != 0 || $warnings != 0) {
                     $count .= '(<span class="errorCount">';
                     $count .= $errors;
                     $count .= '</span>|<span class="warningCount">';
                     $count .= $warnings . '</span>)';
                 }
                 $ret .= str_pad(' ', $indent);
                 $ret .= "<li><a class='treeDir'>{$dirName} {$count}</a>" . PHP_EOL;
                 $indent += $indentStep;
                 $ret .= str_pad(' ', $indent);
                 $ret .= '<ul>' . PHP_EOL;
             }
         }
         $name = str_replace('\\', '/', $name);
         $shortName = substr($name, $preLen);
         $fileName = basename($name);
         $count = '';
         if ($file->getErrorCount() != 0 || $file->getWarningCount() != 0) {
             $count .= '(<span class="errorCount">';
             $count .= $file->getErrorCount();
             $count .= '</span>|<span class="warningCount">';
             $count .= $file->getWarningCount();
             $count .= '</span>)';
         }
         $ret .= str_pad(' ', $indent);
         $ret .= '<li class="php"><a class="fileLink" href="';
         $ret .= $hrefPrefix . $shortName . '.html">';
         $ret .= "{$fileName} {$count}</a></li>" . PHP_EOL;
     }
     while ($indent > $indentStep) {
         $indent -= $indentStep;
         $ret .= str_pad(' ', $indent);
         $ret .= '</ul>' . PHP_EOL;
         $indent -= $indentStep;
         $ret .= str_pad(' ', $indent);
         $ret .= '</li>' . PHP_EOL;
     }
     $ret .= '</ul>' . PHP_EOL;
     return $ret;
 }
Exemple #5
0
 /**
  * Sorting function used in CbFile::sort()
  */
 protected static function _sort($first, $second)
 {
     $first = $first->name();
     $second = $second->name();
     $prefix = CbIOHelper::getCommonPathPrefix(array($first, $second));
     $prelen = strlen($prefix) + 1;
     $first = substr($first, $prelen);
     $second = substr($second, $prelen);
     $firstIsInSubdir = substr_count($first, DIRECTORY_SEPARATOR) !== 0;
     $secondIsInSubdir = substr_count($second, DIRECTORY_SEPARATOR) !== 0;
     if ($firstIsInSubdir) {
         if ($secondIsInSubdir) {
             // both are subdirectories
             return strcmp($first, $second);
         } else {
             // a lies in a subdir of the dir in which b lies,
             // so b comes later.
             return -1;
         }
     } else {
         if ($secondIsInSubdir) {
             // b lies in a subdir of the dir in which a lies,
             // so a comes later.
             return 1;
         } else {
             // both are files
             return strcmp($first, $second);
         }
     }
 }
 /**
  * Test getCommonPathPrefix with empty filelist.
  *
  * @return void
  */
 public function test__getCommonPathPrefixForNoFiles()
 {
     $this->assertEquals('/', $this->_ioHelper->getCommonPathPrefix(array()));
 }
Exemple #7
0
 /**
  * Main execute function for PHP_CodeBrowser.
  *
  * Following steps are resolved:
  * 1. Clean-up output directory
  * 2. Merge xml log files
  * 3. Generate cbXML file via errorlist from plugins
  * 4. Save the cbErrorList as XML file
  * 5. Generate HTML output from cbXML
  * 6. Copy ressources (css, js, images) from template directory to output
  *
  * @return void
  */
 public function run()
 {
     // clear and create output directory
     if (is_dir($this->_htmlOutputDir)) {
         $this->_ioHelper->deleteDirectory($this->_htmlOutputDir);
     } else {
         if (is_file($this->_htmlOutputDir)) {
             $this->_ioHelper->deleteFile($this->_htmlOutputDir);
         }
     }
     $this->_ioHelper->createDirectory($this->_htmlOutputDir);
     // init needed classes
     $cbViewReview = new CbViewReview(PHPCB_TEMPLATE_DIR, $this->_htmlOutputDir, $this->_ioHelper);
     $sourceHandler = new CbSourceHandler();
     if (isset($this->_logDir)) {
         $cbIssueXml = new CbIssueXml();
         // merge xml files
         $cbIssueXml->addDirectory($this->_logDir);
         // conversion of XML file cc to cb format
         foreach ($this->_registeredPlugins as $className) {
             $sourceHandler->addPlugin(new $className($cbIssueXml));
         }
     }
     if (isset($this->_projectSource)) {
         foreach ($this->_projectSource as $source) {
             if (is_dir($source)) {
                 $sourceHandler->addSourceFiles(File_Iterator_Factory::getFileIterator($source, array('php', 'js', 'css', 'html')));
             } else {
                 $sourceHandler->addSourceFile($source);
             }
         }
     }
     array_walk($this->_excludeExpressions, array($sourceHandler, 'excludeMatchingPCRE'));
     array_walk($this->_excludePatterns, array($sourceHandler, 'excludeMatchingPattern'));
     $files = $sourceHandler->getFiles();
     if (!$files) {
         $cbViewReview->copyNoErrorsIndex();
     } else {
         // Get the path prefix all files have in common
         $commonPathPrefix = $sourceHandler->getCommonPathPrefix();
         foreach ($files as $file) {
             $cbViewReview->generate($file->getIssues(), $file->name(), $commonPathPrefix);
         }
         // Copy needed ressources (eg js libraries) to output directory
         $cbViewReview->copyRessourceFolders();
         $cbViewReview->generateIndex($files);
     }
 }