Exemplo n.º 1
0
 /**
  * Test getCommonPathPrefix with empty file list.
  *
  * @return void
  */
 public function testGetCommonPathPrefixForNoFiles()
 {
     $this->assertEquals('/', $this->ioHelper->getCommonPathPrefix(array()));
 }
Exemplo n.º 2
0
 /**
  * Sorting function used in File::sort()
  */
 protected static function internalSort(File $first, File $second)
 {
     $first = $first->name();
     $second = $second->name();
     $prefix = IOHelper::getCommonPathPrefix(array($first, $second));
     $prefixLength = strlen($prefix);
     $first = substr($first, $prefixLength);
     $second = substr($second, $prefixLength);
     $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);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Retrieves the parent directory all files have in common.
  *
  * @return string
  */
 public function getCommonPathPrefix()
 {
     return IOHelper::getCommonPathPrefix(array_keys($this->files));
 }
Exemplo n.º 4
0
 /**
  * Convert a list of files to a html fragment for jstree.
  *
  * @param File[] $fileList       The files, format: array('name' => File).
  * @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 = IOHelper::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;
 }
Exemplo n.º 5
0
 /**
  * Main execute function for PHP_CodeBrowser.
  *
  * Following steps are resolved:
  * 1. Clean-up output directory
  * 2. Merge xml log files
  * 3. Generate XML file via error list from plugins
  * 4. Save the ErrorList as XML file
  * 5. Generate HTML output from XML
  * 6. Copy resources (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);
     } elseif (is_file($this->htmlOutputDir)) {
         $this->ioHelper->deleteFile($this->htmlOutputDir);
     }
     $this->ioHelper->createDirectory($this->htmlOutputDir);
     // init needed classes
     $viewReview = new ViewReview(PHPCB_TEMPLATE_DIR, $this->htmlOutputDir, $this->ioHelper, $this->phpSuffixes);
     $sourceHandler = new SourceHandler($this->debugLog);
     if (isset($this->logDir)) {
         $issueXml = new IssueXml();
         // merge xml files
         $issueXml->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($issueXml, $this->pluginOptions[$className]);
             } else {
                 $plugin = new $className($issueXml);
             }
             $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) {
         $viewReview->copyNoErrorsIndex();
     } else {
         // Get the path prefix all files have in common
         $commonPathPrefix = $sourceHandler->getCommonPathPrefix();
         foreach ($files as $file) {
             $viewReview->generate($file->getIssues(), $file->name(), $commonPathPrefix, $this->excludeOK);
         }
         // Copy needed resources (eg js libraries) to output directory
         $viewReview->copyResourceFolders();
         $viewReview->generateIndex($files, $this->excludeOK);
     }
 }