/**
  * Returns formatter object
  * @param PHPLocFormatterElement $formatterElement
  * @throws BuildException
  * @return AbstractPHPLocFormatter
  */
 public static function createFormatter($formatterElement)
 {
     $formatter = null;
     $type = $formatterElement->getType();
     switch ($type) {
         case "xml":
             require_once 'phing/tasks/ext/phploc/PHPLocXMLFormatter.php';
             $formatter = new PHPLocXMLFormatter();
             break;
         case "csv":
             require_once 'phing/tasks/ext/phploc/PHPLocCSVFormatter.php';
             $formatter = new PHPLocCSVFormatter();
             break;
         case "txt":
         case "cli":
             require_once 'phing/tasks/ext/phploc/PHPLocTextFormatter.php';
             $formatter = new PHPLocTextFormatter();
             break;
         default:
             throw new BuildException("Formatter '" . $type . "' not implemented");
     }
     $formatter->setOutfile($formatterElement->getOutfile());
     $formatter->setToDir($formatterElement->getToDir());
     $formatter->setUseFile($formatterElement->getUseFile());
     return $formatter;
 }
Example #2
0
 /**
  * @throws BuildException
  */
 private function validateProperties()
 {
     if ($this->fileToCheck === null && count($this->fileSets) === 0) {
         throw new BuildException('Missing either a nested fileset or the attribute "file" set.');
     }
     if ($this->fileToCheck !== null) {
         if (!file_exists($this->fileToCheck)) {
             throw new BuildException("File to check doesn't exist.");
         }
         if (!$this->isFileSuffixSet($this->fileToCheck)) {
             throw new BuildException('Suffix of file to check is not defined in "suffixes" attribute.');
         }
         if (count($this->fileSets) > 0) {
             throw new BuildException('Either use a nested fileset or "file" attribute; not both.');
         }
     }
     if (count($this->suffixesToCheck) === 0) {
         throw new BuildException('No file suffix defined.');
     }
     if (count($this->formatterElements) == 0) {
         if ($this->reportType === null) {
             throw new BuildException('No report type or formatters defined.');
         }
         if ($this->reportType !== null && !in_array($this->reportType, $this->acceptedReportTypes)) {
             throw new BuildException('Unaccepted report type defined.');
         }
         if ($this->reportType !== 'cli' && $this->reportDirectory === null) {
             throw new BuildException('No report output directory defined.');
         }
         if ($this->reportDirectory !== null && !is_dir($this->reportDirectory)) {
             $reportOutputDir = new PhingFile($this->reportDirectory);
             $logMessage = "Report output directory doesn't exist, creating: " . $reportOutputDir->getAbsolutePath() . '.';
             $this->log($logMessage);
             $reportOutputDir->mkdirs();
         }
         if ($this->reportType !== 'cli') {
             $this->reportFileName .= '.' . $this->reportType;
         }
         $formatterElement = new PHPLocFormatterElement();
         $formatterElement->setType($this->reportType);
         $formatterElement->setUseFile($this->reportDirectory !== null);
         $formatterElement->setToDir($this->reportDirectory);
         $formatterElement->setOutfile($this->reportFileName);
         $this->formatterElements[] = $formatterElement;
     }
 }