Completed
Pull Request — master (#18)
by SignpostMarv
02:40
created

Group::setDoc()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
1
<?php
2
3
namespace GoetasWebservices\XML\XSDReader\Schema\Attribute;
4
5
use DOMElement;
6
use GoetasWebservices\XML\XSDReader\SchemaReader;
7
use GoetasWebservices\XML\XSDReader\Schema\Schema;
8
9
class Group implements AttributeItem, AttributeContainer
10
{
11
    use AttributeItemTrait;
12
    use AttributeContainerTrait;
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
50 45
        return $this;
51
    }
52
53
    /**
54
     * @return Schema
55
     */
56
    public function getSchema()
57
    {
58
        return $this->schema;
59
    }
60
61
    /**
62
     * @param string $attr
63
     */
64 45
    public static function findSomethingLikeThis(
65
        SchemaReader $useThis,
66
        Schema $schema,
67
        DOMElement $node,
68
        DOMElement $childNode,
69
        AttributeContainer $addToThis
70
    ) {
71
        /**
72
         * @var AttributeItem
73
         */
74 45
        $attribute = $useThis->findSomething('findAttributeGroup', $schema, $node, $childNode->getAttribute('ref'));
75 45
        $addToThis->addAttribute($attribute);
76 45
    }
77
78
    /**
79
     * @return \Closure
80
     */
81 45
    public static function loadAttributeGroup(
82
        SchemaReader $schemaReader,
83
        Schema $schema,
84
        DOMElement $node
85
    ) {
86 45
        $attGroup = new self($schema, $node->getAttribute('name'));
87 45
        $attGroup->setDoc(SchemaReader::getDocumentation($node));
88 45
        $schema->addAttributeGroup($attGroup);
89
90
        return function () use ($schemaReader, $schema, $node, $attGroup) {
91 45
            SchemaReader::againstDOMNodeList(
92 45
                $node,
93 45
                function (
94
                    DOMElement $node,
95
                    DOMElement $childNode
96
                ) use (
97 45
                    $schemaReader,
98 45
                    $schema,
99 45
                    $attGroup
100
                ) {
101 45
                    switch ($childNode->localName) {
102 45
                        case 'attribute':
103 45
                            $attribute = Attribute::getAttributeFromAttributeOrRef(
104 45
                                $schemaReader,
105 45
                                $childNode,
106 45
                                $schema,
107
                                $node
108 45
                            );
109 45
                            $attGroup->addAttribute($attribute);
110 45
                            break;
111 45
                        case 'attributeGroup':
112 1
                            self::findSomethingLikeThis(
113 1
                                $schemaReader,
114 1
                                $schema,
115 1
                                $node,
116 1
                                $childNode,
117
                                $attGroup
118 1
                            );
119 1
                            break;
120 45
                    }
121 45
                }
122 45
            );
123 45
        };
124
    }
125
}
126