/** * 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); } }
/** * @throws \Exception */ public function handle() { \Log::info('QA::PHPCPD Run copy past detector'); $detector = new Detector(new DefaultStrategy()); $finder = new FinderFacade(['app'], []); $files = $finder->findFiles(); foreach ($files as $key => $value) { if (!is_file($value)) { unset($files[$key]); } } $clones = $detector->copyPasteDetection($files); if ($this->getOutput()->getVerbosity() > 1) { $printer = new Text(); $printer->printResult($this->getOutput(), $clones); unset($printer); } $percentage = floatval($clones->getPercentage()); if ($percentage > $this->option('limit')) { $this->error('[Shame] The copy/paste percentage is ' . $percentage); throw new \Exception('Your code is bad, and you should feel bad'); } }