Passed
Push — static-analysis ( 935891...314368 )
by SignpostMarv
02:22
created

Group   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Test Coverage

Coverage 90.48%

Importance

Changes 0
Metric Value
dl 0
loc 111
ccs 38
cts 42
cp 0.9048
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getDoc() 0 3 1
A getSchema() 0 3 1
A findSomethingLikeThis() 0 12 1
A setDoc() 0 5 1
B loadAttributeGroup() 0 39 3
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 45
    public function __construct(Schema $schema, $name)
29
    {
30 45
        $this->schema = $schema;
31 45
        $this->name = $name;
32 45
    }
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 45
    public function setDoc($doc)
48
    {
49 45
        $this->doc = $doc;
50
51 45
        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 45
    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 45
        $attribute = $useThis->findSomething('findAttributeGroup', $schema, $node, $childNode->getAttribute('ref'));
76 45
        $addToThis->addAttribute($attribute);
77 45
    }
78
79
    /**
80
     * @return \Closure
81
     */
82 45
    public static function loadAttributeGroup(
83
        SchemaReaderLoadAbstraction $schemaReader,
84
        Schema $schema,
85
        DOMElement $node
86
    ) {
87 45
        $attGroup = new self($schema, $node->getAttribute('name'));
88 45
        $attGroup->setDoc(SchemaReader::getDocumentation($node));
89 45
        $schema->addAttributeGroup($attGroup);
90
91
        return function () use ($schemaReader, $schema, $node, $attGroup) {
92 45
            SchemaReaderLoadAbstraction::againstDOMNodeList(
93 45
                $node,
94 45
                function (
95
                    DOMElement $node,
96
                    DOMElement $childNode
97
                ) use (
98 45
                    $schemaReader,
99 45
                    $schema,
100 45
                    $attGroup
101
                ) {
102 45
                    switch ($childNode->localName) {
103 45
                        case 'attribute':
104 45
                            $attribute = Attribute::getAttributeFromAttributeOrRef(
105 45
                                $schemaReader,
106 45
                                $childNode,
107 45
                                $schema,
108
                                $node
109 45
                            );
110 45
                            $attGroup->addAttribute($attribute);
111 45
                            break;
112 45
                        case 'attributeGroup':
113 1
                            self::findSomethingLikeThis(
114 1
                                $schemaReader,
115 1
                                $schema,
116 1
                                $node,
117 1
                                $childNode,
118
                                $attGroup
119 1
                            );
120 1
                            break;
121 45
                    }
122 45
                }
123 45
            );
124 45
        };
125
    }
126
}
127