Passed
Push — static-analysis ( d5a974...87b144 )
by SignpostMarv
03:37
created

Group::addAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 1
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 135
    public function __construct(Schema $schema, $name)
28
    {
29 135
        $this->schema = $schema;
30 135
        $this->name = $name;
31 135
    }
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 135
    public function setDoc($doc)
47
    {
48 135
        $this->doc = $doc;
49 135
        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 135
    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 135
        $attribute = $useThis->findSomething('findAttributeGroup', $schema, $node, $childNode->getAttribute("ref"));
74 135
        $addToThis->addAttribute($attribute);
75 135
    }
76
77
    /**
78
    * @return \Closure
79
    */
80 135
    public static function loadAttributeGroup(
81
        SchemaReader $schemaReader,
82
        Schema $schema,
83
        DOMElement $node
84
    ) {
85 135
        $attGroup = new self($schema, $node->getAttribute("name"));
86 135
        $attGroup->setDoc(SchemaReader::getDocumentation($node));
87 135
        $schema->addAttributeGroup($attGroup);
88
89 135
        return function () use ($schemaReader, $schema, $node, $attGroup) {
90 135
            foreach ($node->childNodes as $childNode) {
91 135
                switch ($childNode->localName) {
92 135
                    case 'attribute':
93 135
                        $attribute = Attribute::getAttributeFromAttributeOrRef(
94 135
                            $schemaReader,
95 135
                            $childNode,
96 135
                            $schema,
97 90
                            $node
98 45
                        );
99 135
                        $attGroup->addAttribute($attribute);
100 135
                        break;
101 135
                    case 'attributeGroup':
102 3
                        self::findSomethingLikeThis(
103 3
                            $schemaReader,
104 3
                            $schema,
105 3
                            $node,
106 3
                            $childNode,
107 2
                            $attGroup
108 1
                        );
109 91
                        break;
110 45
                }
111 45
            }
112 135
        };
113
    }
114
}
115