Skip to content

Engine accepts paths to custom ruleset #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 7, 2015
Merged
Changes from 1 commit
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
18 changes: 17 additions & 1 deletion 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 Down Expand Up @@ -63,6 +65,19 @@ 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.

💄 looks like this needs to be indented another column?

}
}

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

public function run($files)
{
$resultFile = tempnam(sys_get_temp_dir(), 'phpmd');
Expand All @@ -78,10 +93,11 @@ 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($rulesets);
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason not to replace these two lines with $rulesets = $this->prefixCodeDirectory($this->config['config']['rulesets'])? Assigning to a var & then immediately reassigning it with a mutated version of itself is kind of smelly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay

}

$phpmd->processFiles(
Expand Down