Passed
Push — static-analysis ( 935891...314368 )
by SignpostMarv
02:22
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
use GoetasWebservices\XML\XSDReader\SchemaReaderLoadAbstraction;
10
11
class Group implements ElementItem, ElementContainer
12
{
13
    use AttributeItemTrait;
14
    use ElementContainerTrait;
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 45
    public function __construct(Schema $schema, $name)
30
    {
31 45
        $this->schema = $schema;
32 45
        $this->name = $name;
33 45
    }
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 45
    public function setDoc($doc)
49
    {
50 45
        $this->doc = $doc;
51
52 45
        return $this;
53
    }
54
55
    /**
56
     * @return Schema
57
     */
58 45
    public function getSchema()
59
    {
60 45
        return $this->schema;
61
    }
62
63
    /**
64
     * @return Group|GroupRef
65
     */
66 45
    protected static function loadGroupBeforeCheckingChildNodes(
67
        Schema $schema,
68
        DOMElement $node
69
    ) {
70 45
        $group = new self($schema, $node->getAttribute('name'));
71 45
        $group->setDoc(SchemaReader::getDocumentation($node));
72
73 45
        if ($node->hasAttribute('maxOccurs')) {
74
            /**
75
             * @var GroupRef
76
             */
77
            $group = SchemaReader::maybeSetMax(new GroupRef($group), $node);
78
        }
79 45
        if ($node->hasAttribute('minOccurs')) {
80
            /**
81
             * @var GroupRef
82
             */
83
            $group = SchemaReader::maybeSetMin(
84
                $group instanceof GroupRef ? $group : new GroupRef($group),
85
                $node
86
            );
87
        }
88
89 45
        $schema->addGroup($group);
90
91 45
        return $group;
92
    }
93
94
    /**
95
     * @return \Closure
96
     */
97 45
    public static function loadGroup(
98
        SchemaReaderLoadAbstraction $reader,
99
        Schema $schema,
100
        DOMElement $node
101
    ) {
102 45
        $group = static::loadGroupBeforeCheckingChildNodes(
103 45
            $schema,
104
            $node
105 45
        );
106
        static $methods = [
107
            'sequence' => 'loadSequence',
108
            'choice' => 'loadSequence',
109
            'all' => 'loadSequence',
110 45
        ];
111
112 45
        return function () use ($reader, $group, $node, $methods) {
113
            /**
114
             * @var string[]
115
             */
116 45
            $methods = $methods;
117 45
            $reader->maybeCallMethodAgainstDOMNodeList(
118 45
                $node,
119 45
                $group,
120
                $methods
121 45
            );
122 45
        };
123
    }
124
}
125