Completed
Pull Request — master (#18)
by SignpostMarv
02:40
created

Group   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Test Coverage

Coverage 76.47%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
dl 0
loc 110
ccs 26
cts 34
cp 0.7647
rs 10
c 3
b 0
f 0
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getDoc() 0 3 1
A __construct() 0 4 1
A getSchema() 0 3 1
A setDoc() 0 5 1
B loadGroupBeforeCheckingChildNodes() 0 26 4
B loadGroup() 0 24 1
1
<?php
2
3
namespace GoetasWebservices\XML\XSDReader\Schema\Element;
4
5
use DOMElement;
6
use GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeItemTrait;
7
use GoetasWebservices\XML\XSDReader\Schema\Schema;
8
use GoetasWebservices\XML\XSDReader\SchemaReader;
9
10
class Group implements ElementItem, ElementContainer
11
{
12
    use AttributeItemTrait;
13
    use ElementContainerTrait;
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 45
    public function getSchema()
58
    {
59 45
        return $this->schema;
60
    }
61
62
    /**
63
     * @return Group|GroupRef
64
     */
65 45
    protected static function loadGroupBeforeCheckingChildNodes(
66
        Schema $schema,
67
        DOMElement $node
68
    ) {
69 45
        $group = new self($schema, $node->getAttribute('name'));
70 45
        $group->setDoc(SchemaReader::getDocumentation($node));
71
72 45
        if ($node->hasAttribute('maxOccurs')) {
73
            /**
74
             * @var GroupRef
75
             */
76
            $group = SchemaReader::maybeSetMax(new GroupRef($group), $node);
77
        }
78 45
        if ($node->hasAttribute('minOccurs')) {
79
            /**
80
             * @var GroupRef
81
             */
82
            $group = SchemaReader::maybeSetMin(
83
                $group instanceof GroupRef ? $group : new GroupRef($group),
84
                $node
85
            );
86
        }
87
88 45
        $schema->addGroup($group);
89
90 45
        return $group;
91
    }
92
93
    /**
94
     * @return \Closure
95
     */
96 45
    public static function loadGroup(
97
        SchemaReader $reader,
98
        Schema $schema,
99
        DOMElement $node
100
    ) {
101 45
        $group = static::loadGroupBeforeCheckingChildNodes(
102 45
            $schema,
103
            $node
104 45
        );
105
        static $methods = [
106
            'sequence' => 'loadSequence',
107
            'choice' => 'loadSequence',
108
            'all' => 'loadSequence',
109 45
        ];
110
111 45
        return function () use ($reader, $group, $node, $methods) {
112
            /**
113
             * @var string[]
114
             */
115 45
            $methods = $methods;
116 45
            $reader->maybeCallMethodAgainstDOMNodeList(
117 45
                $node,
118 45
                $group,
119
                $methods
120 45
            );
121 45
        };
122
    }
123
}
124