Skip to content

Commit 6d5f875

Browse files
committed
Possibility to define arrays as XML elements in ruleset
1 parent fdc4698 commit 6d5f875

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

src/Ruleset.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -945,21 +945,37 @@ private function processRule($rule, $newSniffs, $depth=0)
945945
if (isset($prop['type']) === true
946946
&& (string) $prop['type'] === 'array'
947947
) {
948-
$value = (string) $prop['value'];
949948
$values = [];
950-
foreach (explode(',', $value) as $val) {
951-
list($k, $v) = explode('=>', $val.'=>');
952-
if ($v !== '') {
953-
$values[trim($k)] = trim($v);
954-
} else {
955-
$values[] = trim($k);
949+
if (isset($prop->element) === true) {
950+
foreach ($prop->element as $element) {
951+
if ($this->shouldProcessElement($element) === false) {
952+
continue;
953+
}
954+
955+
$value = (string) $element['value'];
956+
if (isset($element['key']) === true) {
957+
$key = (string) $element['key'];
958+
$values[$key] = $value;
959+
} else {
960+
$values[] = $value;
961+
}
956962
}
957-
}
963+
} else {
964+
$value = (string) $prop['value'];
965+
foreach (explode(',', $value) as $val) {
966+
list($k, $v) = explode('=>', $val.'=>');
967+
if ($v !== '') {
968+
$values[trim($k)] = trim($v);
969+
} else {
970+
$values[] = trim($k);
971+
}
972+
}
973+
}//end if
958974

959975
$this->ruleset[$code]['properties'][$name] = $values;
960976
if (PHP_CODESNIFFER_VERBOSITY > 1) {
961977
echo str_repeat("\t", $depth);
962-
echo "\t\t=> array property \"$name\" set to \"$value\"";
978+
echo "\t\t=> array property \"$name\" set to \"".print_r($values, true).'"';
963979
if ($code !== $ref) {
964980
echo " for $code";
965981
}

0 commit comments

Comments
 (0)