Passed
Branch php-7.1 (52dd08)
by SignpostMarv
03:16
created

Group::loadAttributeGroup()   B

Complexity

Conditions 4
Paths 1

Size

Total Lines 30
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 22
nc 1
nop 3
dl 0
loc 30
ccs 23
cts 23
cp 1
crap 4
rs 8.5806
c 0
b 0
f 0
1
<?php
2
namespace GoetasWebservices\XML\XSDReader\Schema\Attribute;
3
4
use DOMElement;
5
use GoetasWebservices\XML\XSDReader\SchemaReader;
6
use GoetasWebservices\XML\XSDReader\Schema\Schema;
7
8
class Group implements AttributeItem, AttributeContainer
9
{
10
    use AttributeItemTrait;
11
    use AttributeContainerTrait;
12
13
    /**
14
     *
15
     * @var Schema
16
     */
17
    protected $schema;
18
19
    /**
20
    * @var string|null
21
    */
22
    protected $doc;
23
24
    /**
25
    * @param string $name
26
    */
27 45
    public function __construct(Schema $schema, $name)
28
    {
29 45
        $this->schema = $schema;
30 45
        $this->name = $name;
31 45
    }
32
33
    /**
34
    * @return string|null
35
    */
36
    public function getDoc()
37
    {
38
        return $this->doc;
39
    }
40
41
    /**
42
    * @param string $doc
43
    *
44
    * @return $this
45
    */
46 45
    public function setDoc($doc)
47
    {
48 45
        $this->doc = $doc;
49 45
        return $this;
50
    }
51
52
    /**
53
    * @return Schema
54
    */
55
    public function getSchema()
56
    {
57
        return $this->schema;
58
    }
59
60
    /**
61
    * @param string $attr
62
    */
63 45
    public static function findSomethingLikeThis(
64
        SchemaReader $useThis,
65
        Schema $schema,
66
        DOMElement $node,
67
        DOMElement $childNode,
68
        AttributeContainer $addToThis
69
    ) {
70
        /**
71
        * @var AttributeItem $attribute
72
        */
73 45
        $attribute = $useThis->findSomething('findAttributeGroup', $schema, $node, $childNode->getAttribute("ref"));
74 45
        $addToThis->addAttribute($attribute);
75 45
    }
76
77
    /**
78
    * @return \Closure
79
    */
80 45
    public static function loadAttributeGroup(
81
        SchemaReader $schemaReader,
82
        Schema $schema,
83
        DOMElement $node
84
    ) {
85 45
        $attGroup = new self($schema, $node->getAttribute("name"));
86 45
        $attGroup->setDoc(SchemaReader::getDocumentation($node));
87 45
        $schema->addAttributeGroup($attGroup);
88
89 45
        return function () use ($schemaReader, $schema, $node, $attGroup) {
90 45
            foreach ($node->childNodes as $childNode) {
91 45
                switch ($childNode->localName) {
92 45
                    case 'attribute':
93 45
                        $attribute = Attribute::getAttributeFromAttributeOrRef(
94 45
                            $schemaReader,
95 45
                            $childNode,
96 45
                            $schema,
97 45
                            $node
98
                        );
99 45
                        $attGroup->addAttribute($attribute);
100 45
                        break;
101 45
                    case 'attributeGroup':
102 1
                        self::findSomethingLikeThis(
103 1
                            $schemaReader,
104 1
                            $schema,
105 1
                            $node,
106 1
                            $childNode,
107 1
                            $attGroup
108
                        );
109 45
                        break;
110
                }
111
            }
112 45
        };
113
    }
114
}
115