Skip to content
Snippets Groups Projects
Unverified Commit 9349d803 authored by Daniel Siepmann's avatar Daniel Siepmann
Browse files

BUGFIX: Use configured ruleset name as standard name.

Only this way it's possible to include the original standard in own
phpcs configuration.
parent be915d46
Branches
1 merge request!40Feature: Naming
......@@ -57,8 +57,8 @@ class Standard implements StandardInterface
);
}
$this->path = realpath($path);
$this->name = basename($this->path);
$this->ruleSetXmlPath = $path . DIRECTORY_SEPARATOR . static::RULESET_FILENAME;
$this->name = $this->getNameFromRuleSet($this->ruleSetXmlPath);
if (!is_readable($this->ruleSetXmlPath)) {
throw new InvalidStandardException(
......@@ -67,6 +67,22 @@ class Standard implements StandardInterface
}
}
/**
* Fetch PHPCodeSniffer standard name from ruleset.xml.
*
* @param string $ruleSetXmlPath The absolute path to ruleset.xml.
* @return string The name of the PHPCodeSniffer standard.
*/
protected function getNameFromRuleSet($ruleSetXmlPath)
{
try {
$ruleSet = new \SimpleXMLElement(file_get_contents($ruleSetXmlPath));
return (string) $ruleSet->attributes()['name'];
} catch (\Exception $e) {
return basename(dirname($ruleSetXmlPath));
}
}
/**
* Get the name of the PHPCodeSniffer standard.
*
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment