Example #1
0
 /**
  * Executes PHPCPD against PhingFile or a FileSet
  *
  * @throws BuildException
  */
 public function main()
 {
     $this->loadDependencies();
     if (!isset($this->file) && count($this->filesets) == 0) {
         throw new BuildException('Missing either a nested fileset or attribute "file" set');
     }
     if (count($this->formatters) == 0) {
         // turn legacy format attribute into formatter
         $fmt = new PHPCPDFormatterElement($this);
         $fmt->setType($this->format);
         $fmt->setUseFile(false);
         $this->formatters[] = $fmt;
     }
     $this->validateFormatters();
     $filesToParse = array();
     if ($this->file instanceof PhingFile) {
         $filesToParse[] = $this->file->getPath();
     } else {
         // append any files in filesets
         foreach ($this->filesets as $fs) {
             $files = $fs->getDirectoryScanner($this->project)->getIncludedFiles();
             foreach ($files as $filename) {
                 $f = new PhingFile($fs->getDir($this->project), $filename);
                 $filesToParse[] = $f->getAbsolutePath();
             }
         }
     }
     $this->log('Processing files...');
     if ($this->oldVersion) {
         $detectorClass = 'PHPCPD_Detector';
         $strategyClass = 'PHPCPD_Detector_Strategy_Default';
     } else {
         $detectorClass = '\\SebastianBergmann\\PHPCPD\\Detector\\Detector';
         $strategyClass = '\\SebastianBergmann\\PHPCPD\\Detector\\Strategy\\DefaultStrategy';
     }
     $detector = new $detectorClass(new $strategyClass());
     $clones = $detector->copyPasteDetection($filesToParse, $this->minLines, $this->minTokens);
     $this->log('Finished copy/paste detection');
     foreach ($this->formatters as $fe) {
         $formatter = $fe->getFormatter();
         $formatter->processClones($clones, $this->project, $fe->getUseFile(), $fe->getOutfile());
     }
 }
Example #2
0
 /**
  * Executes PHPCPD against PhingFile or a FileSet
  *
  * @return void
  */
 public function main()
 {
     if (!isset($this->_file) and count($this->_filesets) == 0) {
         throw new BuildException("Missing either a nested fileset or attribute 'file' set");
     }
     if (count($this->_formatters) == 0) {
         // turn legacy format attribute into formatter
         $fmt = new PHPCPDFormatterElement($this);
         $fmt->setType($this->_format);
         $fmt->setUseFile(false);
         $this->_formatters[] = $fmt;
     }
     $this->validateFormatters();
     $filesToParse = array();
     if ($this->_file instanceof PhingFile) {
         $filesToParse[] = $this->_file->getPath();
     } else {
         // append any files in filesets
         foreach ($this->_filesets as $fs) {
             $files = $fs->getDirectoryScanner($this->project)->getIncludedFiles();
             foreach ($files as $filename) {
                 $f = new PhingFile($fs->getDir($this->project), $filename);
                 $filesToParse[] = $f->getAbsolutePath();
             }
         }
     }
     $this->log('Processing files...');
     $detector = new PHPCPD_Detector(new PHPCPD_Detector_Strategy_Default());
     $clones = $detector->copyPasteDetection($filesToParse, $this->_minLines, $this->_minTokens);
     $this->log('Finished copy/paste detection');
     foreach ($this->_formatters as $fe) {
         $formatter = $fe->getFormatter();
         $formatter->processClones($clones, $this->project, $fe->getUseFile(), $fe->getOutfile());
     }
 }
 /**
  * Executes PHPCPD against PhingFile or a FileSet
  *
  * @throws BuildException - if the phpcpd classes can't be loaded.
  * @return void
  */
 public function main()
 {
     /**
      * Determine PHPCPD installation
      */
     $oldVersion = false;
     if (!@(include_once 'SebastianBergmann/PHPCPD/autoload.php')) {
         if (!@(include_once 'PHPCPD/Autoload.php')) {
             throw new BuildException('PHPCPDTask depends on PHPCPD being installed ' . 'and on include_path.', $this->getLocation());
         }
         $oldVersion = true;
     } else {
         if (version_compare(PHP_VERSION, '5.3.0') < 0) {
             throw new BuildException("The PHPCPD task now requires PHP 5.3+");
         }
         $oldVersion = false;
     }
     if (!isset($this->_file) and count($this->_filesets) == 0) {
         throw new BuildException("Missing either a nested fileset or attribute 'file' set");
     }
     if (count($this->_formatters) == 0) {
         // turn legacy format attribute into formatter
         $fmt = new PHPCPDFormatterElement($this);
         $fmt->setType($this->_format);
         $fmt->setUseFile(false);
         $this->_formatters[] = $fmt;
     }
     $this->validateFormatters();
     $filesToParse = array();
     if ($this->_file instanceof PhingFile) {
         $filesToParse[] = $this->_file->getPath();
     } else {
         // append any files in filesets
         foreach ($this->_filesets as $fs) {
             $files = $fs->getDirectoryScanner($this->project)->getIncludedFiles();
             foreach ($files as $filename) {
                 $f = new PhingFile($fs->getDir($this->project), $filename);
                 $filesToParse[] = $f->getAbsolutePath();
             }
         }
     }
     $this->log('Processing files...');
     if ($oldVersion) {
         $detectorClass = 'PHPCPD_Detector';
         $strategyClass = 'PHPCPD_Detector_Strategy_Default';
     } else {
         $detectorClass = '\\SebastianBergmann\\PHPCPD\\Detector\\Detector';
         $strategyClass = '\\SebastianBergmann\\PHPCPD\\Detector\\Strategy\\DefaultStrategy';
     }
     $detector = new $detectorClass(new $strategyClass());
     $clones = $detector->copyPasteDetection($filesToParse, $this->_minLines, $this->_minTokens);
     $this->log('Finished copy/paste detection');
     foreach ($this->_formatters as $fe) {
         $formatter = $fe->getFormatter();
         $formatter->processClones($clones, $this->project, $fe->getUseFile(), $fe->getOutfile());
     }
 }