Passed
Push — static-analysis ( 0c4f4f...d5a974 )
by SignpostMarv
03:25
created

Group::getElements()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 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
    use ElementContainerTrait;
11
12
    /**
13
     *
14
     * @var Schema
15
     */
16
    protected $schema;
17
18
    /**
19
    * @var string|null
20
    */
21
    protected $doc;
22
23
    /**
24
    * @var string
25
    */
26
    protected $name;
27
28
    /**
29
    * @param string $name
30
    */
31 135
    public function __construct(Schema $schema, $name)
32
    {
33 135
        $this->schema = $schema;
34 135
        $this->name = $name;
35 135
    }
36
37
    /**
38
    * @return string
39
    */
40 135
    public function getName()
41
    {
42 135
        return $this->name;
43
    }
44
45
    /**
46
    * @param string $name
47
    *
48
    * @return $this
49
    */
50
    public function setName($name)
51
    {
52
        $this->name = $name;
53
        return $this;
54
    }
55
56
    /**
57
    * @return string|null
58
    */
59
    public function getDoc()
60
    {
61
        return $this->doc;
62
    }
63
64
    /**
65
    * @param string $doc
66
    *
67
    * @return $this
68
    */
69 135
    public function setDoc($doc)
70
    {
71 135
        $this->doc = $doc;
72 135
        return $this;
73
    }
74
75
    /**
76
    * @return Schema
77
    */
78 135
    public function getSchema()
79
    {
80 135
        return $this->schema;
81
    }
82
83
    /**
84
    * @return \Closure
85
    */
86 135
    public static function loadGroup(
87
        SchemaReader $reader,
88
        Schema $schema,
89
        DOMElement $node
90
    ) {
91 135
        $group = new Group($schema, $node->getAttribute("name"));
92 135
        $group->setDoc(SchemaReader::getDocumentation($node));
93
94 135
        if ($node->hasAttribute("maxOccurs")) {
95
            /**
96
            * @var GroupRef $group
97
            */
98
            $group = SchemaReader::maybeSetMax(new GroupRef($group), $node);
99
        }
100 135
        if ($node->hasAttribute("minOccurs")) {
101
            /**
102
            * @var GroupRef $group
103
            */
104
            $group = SchemaReader::maybeSetMin(
105
                $group instanceof GroupRef ? $group : new GroupRef($group),
106
                $node
107
            );
108
        }
109
110 135
        $schema->addGroup($group);
111
112 90
        static $methods = [
113
            'sequence' => 'loadSequence',
114
            'choice' => 'loadSequence',
115
            'all' => 'loadSequence',
116 45
        ];
117
118 135
        return function () use ($reader, $group, $node, $methods) {
119 135
            foreach ($node->childNodes as $childNode) {
120 135
                $reader->maybeCallMethod(
121 135
                    $methods,
122 135
                    (string) $childNode->localName,
123 135
                    $childNode,
124 135
                    $group,
125 90
                    $childNode
126 45
                );
127 45
            }
128 135
        };
129
    }
130
}
131