Inheritance: extends AbstractXmlLogger
Exemplo n.º 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);
     }
 }
Exemplo n.º 2
0
 /**
  * Main method.
  */
 public function main()
 {
     $input = new \ezcConsoleInput();
     $input->registerOption(new \ezcConsoleOption('', 'exclude', \ezcConsoleInput::TYPE_STRING, array(), TRUE));
     $input->registerOption(new \ezcConsoleOption('h', 'help', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE));
     $input->registerOption(new \ezcConsoleOption('', 'log-pmd', \ezcConsoleInput::TYPE_STRING));
     $input->registerOption(new \ezcConsoleOption('', 'min-lines', \ezcConsoleInput::TYPE_INT, 5));
     $input->registerOption(new \ezcConsoleOption('', 'min-tokens', \ezcConsoleInput::TYPE_INT, 70));
     $input->registerOption(new \ezcConsoleOption('', 'names', \ezcConsoleInput::TYPE_STRING, '*.php', FALSE));
     $input->registerOption(new \ezcConsoleOption('', 'quiet', \ezcConsoleInput::TYPE_NONE, NULL, FALSE));
     $input->registerOption(new \ezcConsoleOption('v', 'version', \ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE));
     $input->registerOption(new \ezcConsoleOption('', 'progress', \ezcConsoleInput::TYPE_NONE));
     $input->registerOption(new \ezcConsoleOption('', 'verbose', \ezcConsoleInput::TYPE_NONE));
     try {
         $input->process();
     } catch (\ezcConsoleOptionException $e) {
         print $e->getMessage() . "\n";
         exit(1);
     }
     if ($input->getOption('help')->value) {
         $this->showHelp();
         exit(0);
     } else {
         if ($input->getOption('version')->value) {
             $this->printVersionString();
             exit(0);
         }
     }
     $arguments = $input->getArguments();
     if (empty($arguments)) {
         $this->showHelp();
         exit(1);
     }
     $excludes = $input->getOption('exclude')->value;
     $logPmd = $input->getOption('log-pmd')->value;
     $minLines = $input->getOption('min-lines')->value;
     $minTokens = $input->getOption('min-tokens')->value;
     $names = explode(',', $input->getOption('names')->value);
     $quiet = $input->getOption('quiet')->value;
     $verbose = $input->getOption('verbose')->value;
     array_map('trim', $names);
     if ($input->getOption('progress')->value !== FALSE) {
         $output = new \ezcConsoleOutput();
     } else {
         $output = NULL;
     }
     $this->printVersionString();
     $finder = new FinderFacade($arguments, $excludes, $names);
     $files = $finder->findFiles();
     if (empty($files)) {
         $this->showError("No files found to scan.\n");
     }
     $strategy = new DefaultStrategy();
     $detector = new Detector($strategy, $output);
     $clones = $detector->copyPasteDetection($files, $minLines, $minTokens);
     $printer = new ResultPrinter();
     $printer->printResult($clones, !$quiet, $verbose);
     unset($printer);
     if ($logPmd) {
         $pmd = new PMD($logPmd);
         $pmd->processClones($clones);
         unset($pmd);
     }
     if (count($clones) > 0) {
         exit(1);
     }
 }