Passed
Push — static-analysis ( 85afd6...0e0544 )
by SignpostMarv
03:23
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 getSchema() 0 3 1
A __construct() 0 4 1
A getDoc() 0 3 1
A findSomethingLikeThis() 0 12 1
A setDoc() 0 4 1
B loadAttributeGroup() 0 39 3
1
<?php
2
namespace GoetasWebservices\XML\XSDReader\Schema\Attribute;
3
4
use DOMElement;
5
use GoetasWebservices\XML\XSDReader\SchemaReader;
6
use GoetasWebservices\XML\XSDReader\SchemaReaderLoadAbstraction;
7
use GoetasWebservices\XML\XSDReader\Schema\Schema;
8
9
class Group implements AttributeItem, AttributeContainer
10
{
11
    use AttributeItemTrait;
12
    use AttributeContainerTrait;
13
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 135
        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 135
    public static function findSomethingLikeThis(
65
        SchemaReaderLoadAbstraction $useThis,
66
        Schema $schema,
67
        DOMElement $node,
68
        DOMElement $childNode,
69
        AttributeContainer $addToThis
70
    ) {
71
        /**
72
        * @var AttributeItem $attribute
73
        */
74 135
        $attribute = $useThis->findSomething('findAttributeGroup', $schema, $node, $childNode->getAttribute("ref"));
75 135
        $addToThis->addAttribute($attribute);
76 135
    }
77
78
    /**
79
    * @return \Closure
80
    */
81 135
    public static function loadAttributeGroup(
82
        SchemaReaderLoadAbstraction $schemaReader,
83
        Schema $schema,
84
        DOMElement $node
85
    ) {
86 135
        $attGroup = new self($schema, $node->getAttribute("name"));
87 135
        $attGroup->setDoc(SchemaReader::getDocumentation($node));
88 135
        $schema->addAttributeGroup($attGroup);
89
90
        return function () use ($schemaReader, $schema, $node, $attGroup) {
91 135
            SchemaReaderLoadAbstraction::againstDOMNodeList(
92 135
                $node,
93 135
                function (
94
                    DOMElement $node,
95
                    DOMElement $childNode
96
                ) use (
97 135
                    $schemaReader,
98 135
                    $schema,
99 135
                    $attGroup
100
                ) {
101 135
                    switch ($childNode->localName) {
102 135
                        case 'attribute':
103 135
                            $attribute = Attribute::getAttributeFromAttributeOrRef(
104 135
                                $schemaReader,
105 135
                                $childNode,
106 135
                                $schema,
107 90
                                $node
108 45
                            );
109 135
                            $attGroup->addAttribute($attribute);
110 135
                            break;
111 135
                        case 'attributeGroup':
112 3
                            self::findSomethingLikeThis(
113 3
                                $schemaReader,
114 3
                                $schema,
115 3
                                $node,
116 3
                                $childNode,
117 2
                                $attGroup
118 1
                            );
119 3
                            break;
120 45
                    }
121 135
                }
122 45
            );
123 135
        };
124
    }
125
}
126