Passed
Push — static-analysis ( c612e4...4098e3 )
by SignpostMarv
03:32
created

Group   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Test Coverage

Coverage 76.32%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 110
ccs 29
cts 38
cp 0.7632
rs 10
wmc 9

6 Methods

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