SebastianBergmann\PHPCPD\Log\PMD::processClones PHP Method

processClones() public method

Processes a list of clones.
public processClones ( CodeCloneMap $clones )
$clones SebastianBergmann\PHPCPD\CodeCloneMap
    public function processClones(CodeCloneMap $clones)
    {
        $cpd = $this->document->createElement('pmd-cpd');
        $this->document->appendChild($cpd);
        foreach ($clones as $clone) {
            $duplication = $cpd->appendChild($this->document->createElement('duplication'));
            $duplication->setAttribute('lines', $clone->getSize());
            $duplication->setAttribute('tokens', $clone->getTokens());
            foreach ($clone->getFiles() as $codeCloneFile) {
                $file = $duplication->appendChild($this->document->createElement('file'));
                $file->setAttribute('path', $codeCloneFile->getName());
                $file->setAttribute('line', $codeCloneFile->getStartLine());
            }
            $duplication->appendChild($this->document->createElement('codefragment', htmlspecialchars($this->convertToUtf8($clone->getLines()), ENT_COMPAT, 'UTF-8')));
        }
        $this->flush();
    }

Usage Example

Example #1
0
 /**
  * Executes the current command.
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return null|integer null or 0 if everything went fine, or an error code
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $finder = new FinderFacade($input->getArgument('values'), $input->getOption('exclude'), $this->handleCSVOption($input, 'names'), $this->handleCSVOption($input, 'names-exclude'));
     $files = $finder->findFiles();
     if (empty($files)) {
         $output->writeln('No files found to scan');
         exit(1);
     }
     $progressHelper = null;
     if ($input->getOption('progress')) {
         $progressHelper = $this->getHelperSet()->get('progress');
         $progressHelper->start($output, count($files));
     }
     $strategy = new DefaultStrategy();
     $detector = new Detector($strategy, $progressHelper);
     $quiet = $output->getVerbosity() == OutputInterface::VERBOSITY_QUIET;
     $clones = $detector->copyPasteDetection($files, $input->getOption('min-lines'), $input->getOption('min-tokens'), $input->getOption('fuzzy'));
     if ($input->getOption('progress')) {
         $progressHelper->finish();
         $output->writeln('');
     }
     if (!$quiet) {
         $printer = new Text();
         $printer->printResult($output, $clones);
         unset($printer);
     }
     $logPmd = $input->getOption('log-pmd');
     if ($logPmd) {
         $pmd = new PMD($logPmd);
         $pmd->processClones($clones);
         unset($pmd);
     }
     if (!$quiet) {
         print \PHP_Timer::resourceUsage() . "\n";
     }
     if (count($clones) > 0) {
         exit(1);
     }
 }
All Usage Examples Of SebastianBergmann\PHPCPD\Log\PMD::processClones