processFiles() public method

This method will process all files that can be found in the given input path. It will apply rules defined in the comma-separated $ruleSets argument. The result will be passed to all given renderer instances.
public processFiles ( string $inputPath, string $ruleSets, array $renderers, RuleSetFactory $ruleSetFactory ) : void
$inputPath string
$ruleSets string
$renderers array
$ruleSetFactory RuleSetFactory
return void
 /**
  * testLocalVariableUsedInDoubleQuoteStringGetsNotReported
  *
  * @return void
  * @outputBuffering enabled
  */
 public function testLocalVariableUsedInDoubleQuoteStringGetsNotReported()
 {
     $renderer = new TextRenderer();
     $renderer->setWriter(new StreamWriter(self::createTempFileUri()));
     $inputs = self::createCodeResourceUriForTest();
     $rules = 'unusedcode';
     $renderes = array($renderer);
     $factory = new RuleSetFactory();
     $phpmd = new PHPMD();
     $phpmd->processFiles($inputs, $rules, $renderes, $factory);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->outputHeading($output, 'PHP Mess Detector on %s');
     $files = $this->plugin->getFiles(Finder::create()->name('*.php'));
     if (count($files) === 0) {
         return $this->outputSkip($output);
     }
     $validate = new Validate();
     $rules = realpath($validate->filePath($input->getOption('rules')));
     $renderer = new MessDetectorRenderer($output, $this->moodle->directory);
     $renderer->setWriter(new StreamWriter(STDOUT));
     $ruleSetFactory = new RuleSetFactory();
     $ruleSetFactory->setMinimumPriority(5);
     $messDetector = new PHPMD();
     $messDetector->processFiles(implode(',', $files), $rules, [$renderer], $ruleSetFactory);
 }
Beispiel #3
0
 public function run($files)
 {
     $resultFile = tempnam(sys_get_temp_dir(), 'phpmd');
     $renderer = new JSONRenderer();
     $renderer->setWriter(new StreamWriter($resultFile));
     $ruleSetFactory = new RuleSetFactory();
     $phpmd = new PHPMD();
     if (isset($this->config['config']['file_extensions'])) {
         $phpmd->setFileExtensions(explode(',', $this->config['config']['file_extensions']));
     }
     $rulesets = Runner::RULESETS;
     if (isset($this->config['config']['rulesets'])) {
         $rulesets = $this->prefixCodeDirectory($this->config['config']['rulesets']);
     }
     $phpmd->processFiles(implode(",", $files), $rulesets, array($renderer), $ruleSetFactory);
     return $resultFile;
 }
Beispiel #4
0
 /**
  * This method creates a PHPMD instance and configures this object based
  * on the user's input, then it starts the source analysis.
  *
  * The return value of this method can be used as an exit code. A value
  * equal to <b>EXIT_SUCCESS</b> means that no violations or errors were
  * found in the analyzed code. Otherwise this method will return a value
  * equal to <b>EXIT_VIOLATION</b>.
  *
  * @param \PHPMD\TextUI\CommandLineOptions $opts
  * @param \PHPMD\RuleSetFactory $ruleSetFactory
  * @return integer
  */
 public function run(CommandLineOptions $opts, RuleSetFactory $ruleSetFactory)
 {
     if ($opts->hasVersion()) {
         fwrite(STDOUT, sprintf('PHPMD %s', $this->getVersion()) . PHP_EOL);
         return self::EXIT_SUCCESS;
     }
     // Create a report stream
     if ($opts->getReportFile() === null) {
         $stream = STDOUT;
     } else {
         $stream = fopen($opts->getReportFile(), 'wb');
     }
     // Create renderer and configure output
     $renderer = $opts->createRenderer();
     $renderer->setWriter(new StreamWriter($stream));
     $renderers = array($renderer);
     foreach ($opts->getReportFiles() as $reportFormat => $reportFile) {
         $reportRenderer = $opts->createRenderer($reportFormat);
         $reportRenderer->setWriter(new StreamWriter(fopen($reportFile, 'wb')));
         $renderers[] = $reportRenderer;
     }
     // Configure a rule set factory
     $ruleSetFactory->setMinimumPriority($opts->getMinimumPriority());
     if ($opts->hasStrict()) {
         $ruleSetFactory->setStrict();
     }
     $phpmd = new PHPMD();
     $phpmd->setOptions(array_filter(array('coverage' => $opts->getCoverageReport())));
     $extensions = $opts->getExtensions();
     if ($extensions !== null) {
         $phpmd->setFileExtensions(explode(',', $extensions));
     }
     $ignore = $opts->getIgnore();
     if ($ignore !== null) {
         $phpmd->setIgnorePattern(explode(',', $ignore));
     }
     $phpmd->processFiles($opts->getInputPath(), $opts->getRuleSets(), $renderers, $ruleSetFactory);
     if ($phpmd->hasViolations()) {
         return self::EXIT_VIOLATION;
     }
     return self::EXIT_SUCCESS;
 }
 /**
  * testCliAcceptsSingleFileAsInput
  *
  * @return void
  */
 public function testCliAcceptsSingleFileAsInput()
 {
     self::changeWorkingDirectory();
     $renderer = new XMLRenderer();
     $renderer->setWriter(new WriterStub());
     $phpmd = new PHPMD();
     $phpmd->processFiles(self::createFileUri('source/FooBar.php'), 'pmd-refset1', array($renderer), new RuleSetFactory());
 }
Beispiel #6
0
        if (!in_array($file, $config["exclude_paths"])) {
            $files[] = "/code/" . $file;
        }
    }
} else {
    foreach ($all_files as $file) {
        if (!in_array($file, $ignorePatterns)) {
            $files[] = "/code/" . $file;
        }
    }
}
$phpmd = new PHPMD();
// if ($extensions !== null) {
//     $phpmd->setFileExtensions(explode(',', $extensions));
// }
$phpmd->processFiles(implode(",", $files), "cleancode,codesize,controversial,design,naming,unusedcode", array($renderer), $ruleSetFactory);
function scandir_recursive($dir, $prefix = '')
{
    $dir = rtrim($dir, '\\/');
    $result = array();
    foreach (scandir($dir) as $f) {
        if ($f !== '.' and $f !== '..') {
            if (is_dir("{$dir}/{$f}")) {
                $result = array_merge($result, scandir_recursive("{$dir}/{$f}", "{$prefix}{$f}/"));
            } else {
                $result[] = $prefix . $f;
            }
        }
    }
    return $result;
}
Beispiel #7
0
 /**
  * testHasViolationsReturnsTrueForSourceWithViolation
  *
  * @return void
  */
 public function testHasViolationsReturnsTrueForSourceWithViolation()
 {
     self::changeWorkingDirectory();
     $renderer = new XMLRenderer();
     $renderer->setWriter(new WriterStub());
     $phpmd = new PHPMD();
     $phpmd->processFiles(self::createFileUri('source/source_with_npath_violation.php'), 'pmd-refset1', array($renderer), new RuleSetFactory());
     $this->assertTrue($phpmd->hasViolations());
 }