Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/IgnoredPaths.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}", '\*,', '\*', ','));
Expand Down
24 changes: 24 additions & 0 deletions src/Tools/Analyzer/Phpmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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;
}
}
8 changes: 8 additions & 0 deletions tests/IgnoredPathsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading