Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

class Runner
{
const RULESETS = 'cleancode,codesize,controversial,design,naming,unusedcode';

private $config;
private $server;

Expand All @@ -20,7 +22,7 @@ public function __construct($config, $server)

public function queueDirectory($dir, $prefix = '')
{
if(isset($this->config['include_paths'])) {
if (isset($this->config['include_paths'])) {
$this->queueWithIncludePaths();
} else {
$this->queuePaths($dir, $prefix, $this->config['exclude_paths']);
Expand All @@ -29,21 +31,21 @@ public function queueDirectory($dir, $prefix = '')
$this->server->process_work(false);
}

public function queueWithIncludePaths() {
public function queueWithIncludePaths()
{
foreach ($this->config['include_paths'] as $f) {
if ($f !== '.' and $f !== '..') {

if (is_dir("/code$f")) {
$this->queuePaths("/code$f", "$f/");
continue;
}

$this->server->addwork(array("/code/$f"));
}
}
}

public function queuePaths($dir, $prefix = '', $exclusions = []) {
public function queuePaths($dir, $prefix = '', $exclusions = [])
{
$dir = rtrim($dir, '\\/');

foreach (scandir($dir) as $f) {
Expand All @@ -63,6 +65,20 @@ public function queuePaths($dir, $prefix = '', $exclusions = []) {
}
}

public function prefixCodeDirectory($configRulesets)
{
$officialPhpRulesets = explode(',', Runner::RULESETS);
$configRulesets = explode(',', $configRulesets);

foreach ($configRulesets as &$r) {
if (!in_array($r, $officialPhpRulesets)) {
$r = "/code/$r";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be worth it to detect the case where someone enters an absolute path (ie. don't prepend /code if the string starts with /)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
}

return implode(',', $configRulesets);
}

public function run($files)
{
$resultFile = tempnam(sys_get_temp_dir(), 'phpmd');
Expand All @@ -78,10 +94,12 @@ public function run($files)
$phpmd->setFileExtensions(explode(',', $this->config['config']['file_extensions']));
}

$rulesets = "cleancode,codesize,controversial,design,naming,unusedcode";
$rulesets = Runner::RULESETS;

if (isset($this->config['config']['rulesets'])) {
$rulesets = $this->config['config']['rulesets'];
$rulesets = $this->prefixCodeDirectory(
$this->config['config']['rulesets']
);
}

$phpmd->processFiles(
Expand Down