| Conditions | 5 |
| Paths | 8 |
| Total Lines | 31 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 5 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | 2 | public function getReferencingElements(): array |
|
| 12 | { |
||
| 13 | 2 | $elements = []; |
|
| 14 | 2 | $attributeGroups = $this->getDomDocumentHandler()->getElementsByNameAndAttributes(AbstractDocument::TAG_ATTRIBUTE_GROUP, [ |
|
| 15 | 2 | 'ref' => sprintf('*:%s', $this->getAttributeName()), |
|
| 16 | 2 | ]); |
|
| 17 | /* |
||
| 18 | * In case of a referencing element that use this attributeGroup that is not namespaced, |
||
| 19 | * use the non namespaced value |
||
| 20 | */ |
||
| 21 | 2 | if (empty($attributeGroups)) { |
|
| 22 | 2 | $attributeGroups = $this->getDomDocumentHandler()->getElementsByNameAndAttributes(AbstractDocument::TAG_ATTRIBUTE_GROUP, [ |
|
| 23 | 2 | 'ref' => sprintf('*%s', $this->getAttributeName()), |
|
| 24 | 2 | ]); |
|
| 25 | } |
||
| 26 | |||
| 27 | /** @var AbstractTag $attributeGroup */ |
||
| 28 | 2 | foreach ($attributeGroups as $attributeGroup) { |
|
| 29 | 2 | $parent = $attributeGroup->getSuitableParent(); |
|
| 30 | /* |
||
| 31 | * In this case, this means the attribute is included in another attribute group, |
||
| 32 | * this means we must climb to its parent recursively until we find the elements referencing the top attributeGroup tag |
||
| 33 | */ |
||
| 34 | 2 | if ($parent instanceof TagAttributeGroup) { |
|
| 35 | 2 | $elements = array_merge($elements, $parent->getReferencingElements()); |
|
| 36 | 2 | } elseif ($parent instanceof AbstractTag) { |
|
| 37 | 2 | $elements[] = $parent; |
|
| 38 | } |
||
| 39 | } |
||
| 40 | |||
| 41 | 2 | return $elements; |
|
| 42 | } |
||
| 44 |