Passed
Push — static-analysis ( 5a0c71...7ccf34 )
by SignpostMarv
03:20
created

Group   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 135
Duplicated Lines 0 %

Test Coverage

Coverage 72.72%

Importance

Changes 0
Metric Value
dl 0
loc 135
ccs 32
cts 44
cp 0.7272
rs 10
c 0
b 0
f 0
wmc 13

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getSchema() 0 3 1
A getElements() 0 3 1
A setDoc() 0 4 1
A getDoc() 0 3 1
A setName() 0 4 1
B loadGroup() 0 40 5
A __construct() 0 4 1
A addElement() 0 3 1
A getName() 0 3 1
1
<?php
2
namespace GoetasWebservices\XML\XSDReader\Schema\Element;
3
4
use DOMElement;
5
use GoetasWebservices\XML\XSDReader\Schema\Schema;
6
use GoetasWebservices\XML\XSDReader\SchemaReader;
7
8
class Group implements ElementItem, ElementContainer
9
{
10
11
    /**
12
     *
13
     * @var Schema
14
     */
15
    protected $schema;
16
17
    /**
18
    * @var string|null
19
    */
20
    protected $doc;
21
22
    /**
23
    * @var string
24
    */
25
    protected $name;
26
27
    /**
28
    * @var ElementItem[]
29
    */
30
    protected $elements = array();
31
32
    /**
33
    * @param string $name
34
    */
35 135
    public function __construct(Schema $schema, $name)
36
    {
37 135
        $this->schema = $schema;
38 135
        $this->name = $name;
39 135
    }
40
41
    /**
42
    * @return string
43
    */
44 135
    public function getName()
45
    {
46 135
        return $this->name;
47
    }
48
49
    /**
50
    * @param string $name
51
    *
52
    * @return $this
53
    */
54
    public function setName($name)
55
    {
56
        $this->name = $name;
57
        return $this;
58
    }
59
60
    /**
61
    * @return ElementItem[]
62
    */
63 6
    public function getElements()
64
    {
65 6
        return $this->elements;
66
    }
67
68 135
    public function addElement(ElementItem $element)
69
    {
70 135
        $this->elements[] = $element;
71 135
    }
72
73
    /**
74
    * @return string|null
75
    */
76
    public function getDoc()
77
    {
78
        return $this->doc;
79
    }
80
81
    /**
82
    * @param string $doc
83
    *
84
    * @return $this
85
    */
86 135
    public function setDoc($doc)
87
    {
88 135
        $this->doc = $doc;
89 135
        return $this;
90
    }
91
92
    /**
93
    * @return Schema
94
    */
95 135
    public function getSchema()
96
    {
97 135
        return $this->schema;
98
    }
99
100
    /**
101
    * @return \Closure
102
    */
103 135
    public static function loadGroup(
104
        SchemaReader $reader,
105
        Schema $schema,
106
        DOMElement $node
107
    ) {
108 135
        $group = new Group($schema, $node->getAttribute("name"));
109 135
        $group->setDoc(SchemaReader::getDocumentation($node));
110
111 135
        if ($node->hasAttribute("maxOccurs")) {
112
            /**
113
            * @var GroupRef $group
114
            */
115
            $group = SchemaReader::maybeSetMax(new GroupRef($group), $node);
116
        }
117 135
        if ($node->hasAttribute("minOccurs")) {
118
            /**
119
            * @var GroupRef $group
120
            */
121
            $group = SchemaReader::maybeSetMin(
122
                $group instanceof GroupRef ? $group : new GroupRef($group),
123
                $node
124
            );
125
        }
126
127 135
        $schema->addGroup($group);
128
129 90
        static $methods = [
130
            'sequence' => 'loadSequence',
131
            'choice' => 'loadSequence',
132
            'all' => 'loadSequence',
133 45
        ];
134
135 135
        return function () use ($reader, $group, $node, $methods) {
136 135
            foreach ($node->childNodes as $childNode) {
137 135
                $reader->maybeCallMethod(
138 135
                    $methods,
139 135
                    (string) $childNode->localName,
140 135
                    $childNode,
141 135
                    $group,
142 90
                    $childNode
143 45
                );
144 45
            }
145 135
        };
146
    }
147
}
148