diff --git a/src/IgnoredPaths.php b/src/IgnoredPaths.php index 7acdb72..5887eb6 100644 --- a/src/IgnoredPaths.php +++ b/src/IgnoredPaths.php @@ -50,6 +50,20 @@ public function phpmd() return $this->ignore(" --exclude /", '/,/', '/', ',/'); } + public function phpmd3() + { + $parts = []; + foreach ($this->ignoreDirs as $dir) { + $dir = trim($dir, '/'); + $parts[] = '--exclude ' . escapeshellarg('*' . $dir . '/*'); + } + foreach ($this->ignoreFiles as $file) { + $file = ltrim($file, '/'); + $parts[] = '--exclude ' . escapeshellarg('*' . $file); + } + return $parts ? ' ' . implode(' ', $parts) : ''; + } + private function pdependWindowsFilter($option) { return str_replace('/', '\\', $this->ignore(" --{$option}", '\*,', '\*', ',')); diff --git a/src/Tools/Analyzer/Phpmd.php b/src/Tools/Analyzer/Phpmd.php index 2f225b4..6e0c50c 100644 --- a/src/Tools/Analyzer/Phpmd.php +++ b/src/Tools/Analyzer/Phpmd.php @@ -20,6 +20,10 @@ public function __invoke() $this->tool->errorsType = $this->config->value('phpmd.ignoreParsingErrors') === true; $rulesets = $this->config->pathsOrValues('phpmd.standard'); + if ($this->toolVersionIs('>=', '3')) { + return $this->buildArgsV3($rulesets); + } + $args = array( $this->options->getAnalyzedDirs(','), $this->options->isSavedToFiles ? 'xml' : 'text', @@ -32,4 +36,24 @@ public function __invoke() } return $args; } + + private function buildArgsV3(array $rulesets) + { + $extensions = array_filter(array_map('trim', explode(',', $this->config->csv('phpqa.extensions')))); + $suffixArgs = ' ' . implode(' ', array_map(function ($ext) { + return '--suffixes ' . $ext; + }, $extensions)); + + $args = []; + $args[] = 'analyze'; + $args[] = $this->options->ignore->phpmd3(); + $args[] = $suffixArgs; + $args['ruleset'] = \Edge\QA\escapePath(implode(',', $rulesets)); + $args['format'] = $this->options->isSavedToFiles ? 'xml' : 'text'; + if ($this->options->isSavedToFiles) { + $args['reportfile-xml'] = $this->tool->getEscapedXmlFile(); + } + $args[] = '-- ' . $this->options->getAnalyzedDirs(' '); + return $args; + } } diff --git a/tests/IgnoredPathsTest.php b/tests/IgnoredPathsTest.php index 193477a..c805e48 100644 --- a/tests/IgnoredPathsTest.php +++ b/tests/IgnoredPathsTest.php @@ -64,6 +64,14 @@ public function provideTools() 'files' => ' --exclude /autoload.php,/RoboFile.php' ) ), + array( + 'phpmd3', + array( + 'both' => " --exclude '*app/config/*' --exclude '*vendor/*' --exclude '*autoload.php' --exclude '*RoboFile.php'", + 'dirs' => " --exclude '*app/config/*' --exclude '*vendor/*'", + 'files' => " --exclude '*autoload.php' --exclude '*RoboFile.php'" + ) + ), 'pdepend + windows' => array( 'pdepend', array(