Commit 9349d803 authored by Daniel Siepmann's avatar Daniel Siepmann

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
......@@ -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.
*
......
Markdown is supported
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