private function parseRuleSetNode($fileName)
{
// Hide error messages
$libxml = libxml_use_internal_errors(true);
$xml = simplexml_load_string(file_get_contents($fileName));
if ($xml === false) {
// Reset error handling to previous setting
libxml_use_internal_errors($libxml);
throw new \RuntimeException(trim(libxml_get_last_error()->message));
}
$ruleSet = new RuleSet();
$ruleSet->setFileName($fileName);
$ruleSet->setName((string) $xml['name']);
if ($this->strict) {
$ruleSet->setStrict();
}
foreach ($xml->children() as $node) {
if ($node->getName() === 'php-includepath') {
$includePath = (string) $node;
if (is_dir(dirname($fileName) . DIRECTORY_SEPARATOR . $includePath)) {
$includePath = dirname($fileName) . DIRECTORY_SEPARATOR . $includePath;
$includePath = realpath($includePath);
}
$includePath = get_include_path() . PATH_SEPARATOR . $includePath;
set_include_path($includePath);
}
}
foreach ($xml->children() as $node) {
if ($node->getName() === 'description') {
$ruleSet->setDescription((string) $node);
} elseif ($node->getName() === 'rule') {
$this->parseRuleNode($ruleSet, $node);
}
}
return $ruleSet;
}