TagAttributeGroup   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 33
ccs 16
cts 16
cp 1
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A getReferencingElements() 0 31 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WsdlToPhp\WsdlHandler\Tag;
6
7
use WsdlToPhp\WsdlHandler\AbstractDocument;
8
9
class TagAttributeGroup extends Tag
10
{
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
    }
43
}
44