Passed
Branch php-7.1 (52dd08)
by SignpostMarv
03:16
created

Group   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
dl 0
loc 95
ccs 24
cts 30
cp 0.8
rs 10
c 0
b 0
f 0
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getSchema() 0 3 1
A setDoc() 0 4 1
A getDoc() 0 3 1
A __construct() 0 4 1
B loadGroup() 0 40 5
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
9
class Group implements ElementItem, ElementContainer
10
{
11
    use AttributeItemTrait;
12
    use ElementContainerTrait;
13
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 45
        return $this;
51
    }
52
53
    /**
54
    * @return Schema
55
    */
56 45
    public function getSchema()
57
    {
58 45
        return $this->schema;
59
    }
60
61
    /**
62
    * @return \Closure
63
    */
64 45
    public static function loadGroup(
65
        SchemaReader $reader,
66
        Schema $schema,
67
        DOMElement $node
68
    ) {
69 45
        $group = new Group($schema, $node->getAttribute("name"));
70 45
        $group->setDoc(SchemaReader::getDocumentation($node));
71
72 45
        if ($node->hasAttribute("maxOccurs")) {
73
            /**
74
            * @var GroupRef $group
75
            */
76
            $group = SchemaReader::maybeSetMax(new GroupRef($group), $node);
77
        }
78 45
        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 45
        $schema->addGroup($group);
89
90 45
        static $methods = [
91
            'sequence' => 'loadSequence',
92
            'choice' => 'loadSequence',
93
            'all' => 'loadSequence',
94
        ];
95
96 45
        return function () use ($reader, $group, $node, $methods) {
97 45
            foreach ($node->childNodes as $childNode) {
98 45
                $reader->maybeCallMethod(
99 45
                    $methods,
100 45
                    (string) $childNode->localName,
101 45
                    $childNode,
102 45
                    $group,
103 45
                    $childNode
104
                );
105
            }
106 45
        };
107
    }
108
}
109