28 private $exceptionCollector;
37 $this->uniqueKey = $uniqueKey;
38 $this->exceptionCollector = $exceptionCollector;
50 $childNodes = $parentNode->childNodes;
51 $type = ucfirst($parentNode->tagName);
54 for (
$i = 0;
$i < $childNodes->length;
$i++) {
55 $currentNode = $childNodes->item(
$i);
57 if (!is_a($currentNode, \DOMElement::class)) {
61 if ($currentNode->hasAttribute($this->uniqueKey)) {
62 $keyValues[] = $currentNode->getAttribute($this->uniqueKey);
66 $withoutDuplicates = array_unique($keyValues);
68 if (count($withoutDuplicates) != count($keyValues)) {
69 $duplicates = array_diff_assoc($keyValues, $withoutDuplicates);
71 foreach ($duplicates as $duplicateKey => $duplicateValue) {
72 $keyError .=
"\t{$this->uniqueKey}: {$duplicateValue} is used more than once.";
73 if ($parentKey !==
null) {
74 $keyError .=
" (Parent: {$parentKey})";
79 $errorMsg =
"{$type} cannot use {$this->uniqueKey}s more than once.\t\n{$keyError}\tin file: {$filename}";
80 $this->exceptionCollector->addError($filename, $errorMsg);
validateChildUniqueness(\DOMElement $parentNode, $filename, $parentKey)
__construct($uniqueKey, $exceptionCollector)