Passed
Pull Request — master (#18)
by SignpostMarv
03:22
created

Group   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 111
ccs 40
cts 44
cp 0.9091
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getDoc() 0 3 1
A getSchema() 0 3 1
B loadAttributeGroup() 0 39 3
A findSomethingLikeThis() 0 12 1
A setDoc() 0 5 1
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\SchemaReaderLoadAbstraction;
8
use GoetasWebservices\XML\XSDReader\Schema\Schema;
9
10
class Group implements AttributeItem, AttributeContainer
11
{
12
    use AttributeItemTrait;
13
    use AttributeContainerTrait;
14
15
    /**
16
     * @var Schema
17
     */
18
    protected $schema;
19
20
    /**
21
     * @var string|null
22
     */
23
    protected $doc;
24
25
    /**
26
     * @param string $name
27
     */
28 135
    public function __construct(Schema $schema, $name)
29
    {
30 135
        $this->schema = $schema;
31 135
        $this->name = $name;
32 135
    }
33
34
    /**
35
     * @return string|null
36
     */
37
    public function getDoc()
38
    {
39
        return $this->doc;
40
    }
41
42
    /**
43
     * @param string $doc
44
     *
45
     * @return $this
46
     */
47 135
    public function setDoc($doc)
48
    {
49 135
        $this->doc = $doc;
50
51 135
        return $this;
52
    }
53
54
    /**
55
     * @return Schema
56
     */
57
    public function getSchema()
58
    {
59
        return $this->schema;
60
    }
61
62
    /**
63
     * @param string $attr
64
     */
65 135
    public static function findSomethingLikeThis(
66
        SchemaReaderLoadAbstraction $useThis,
67
        Schema $schema,
68
        DOMElement $node,
69
        DOMElement $childNode,
70
        AttributeContainer $addToThis
71
    ) {
72
        /**
73
         * @var AttributeItem
74
         */
75 135
        $attribute = $useThis->findSomething('findAttributeGroup', $schema, $node, $childNode->getAttribute('ref'));
76 135
        $addToThis->addAttribute($attribute);
77 135
    }
78
79
    /**
80
     * @return \Closure
81
     */
82 135
    public static function loadAttributeGroup(
83
        SchemaReaderLoadAbstraction $schemaReader,
84
        Schema $schema,
85
        DOMElement $node
86
    ) {
87 135
        $attGroup = new self($schema, $node->getAttribute('name'));
88 135
        $attGroup->setDoc(SchemaReader::getDocumentation($node));
89 135
        $schema->addAttributeGroup($attGroup);
90
91
        return function () use ($schemaReader, $schema, $node, $attGroup) {
92 135
            SchemaReaderLoadAbstraction::againstDOMNodeList(
93 135
                $node,
94 135
                function (
95
                    DOMElement $node,
96
                    DOMElement $childNode
97
                ) use (
98 135
                    $schemaReader,
99 135
                    $schema,
100 135
                    $attGroup
101
                ) {
102 135
                    switch ($childNode->localName) {
103 135
                        case 'attribute':
104 135
                            $attribute = Attribute::getAttributeFromAttributeOrRef(
105 135
                                $schemaReader,
106 135
                                $childNode,
107 135
                                $schema,
108 90
                                $node
109 45
                            );
110 135
                            $attGroup->addAttribute($attribute);
111 135
                            break;
112 135
                        case 'attributeGroup':
113 3
                            self::findSomethingLikeThis(
114 3
                                $schemaReader,
115 3
                                $schema,
116 3
                                $node,
117 3
                                $childNode,
118 2
                                $attGroup
119 1
                            );
120 3
                            break;
121 45
                    }
122 135
                }
123 45
            );
124 135
        };
125
    }
126
}
127