Test Failed
Pull Request — master (#18)
by SignpostMarv
02:37
created

Group::loadGroup()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 40
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 21
nc 4
nop 3
dl 0
loc 40
rs 8.439
c 0
b 0
f 0
ccs 0
cts 0
cp 0
crap 30
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 45
    * @var string|null
22
    */
23 45
    protected $doc;
24 45
25 45
    /**
26
    * @param string $name
27 45
    */
28
    public function __construct(Schema $schema, $name)
29 45
    {
30
        $this->schema = $schema;
31
        $this->name = $name;
32
    }
33
34
    /**
35
    * @return string|null
36
    */
37
    public function getDoc()
38 2
    {
39
        return $this->doc;
40 2
    }
41
42
    /**
43 45
    * @param string $doc
44
    *
45 45
    * @return $this
46 45
    */
47
    public function setDoc($doc)
48
    {
49
        $this->doc = $doc;
50
        return $this;
51
    }
52
53 45
    /**
54
    * @return Schema
55 45
    */
56 45
    public function getSchema()
57
    {
58
        return $this->schema;
59 45
    }
60
61 45
    /**
62
    * @return \Closure
63
    */
64
    public static function loadGroup(
65
        SchemaReader $reader,
66
        Schema $schema,
67
        DOMElement $node
68
    ) {
69
        $group = new Group($schema, $node->getAttribute("name"));
70
        $group->setDoc(SchemaReader::getDocumentation($node));
71
72
        if ($node->hasAttribute("maxOccurs")) {
73
            /**
74
            * @var GroupRef $group
75
            */
76
            $group = SchemaReader::maybeSetMax(new GroupRef($group), $node);
77
        }
78
        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
        $schema->addGroup($group);
89
90
        static $methods = [
91
            'sequence' => 'loadSequence',
92
            'choice' => 'loadSequence',
93
            'all' => 'loadSequence',
94
        ];
95
96
        return function () use ($reader, $group, $node, $methods) {
97
            foreach ($node->childNodes as $childNode) {
98
                $reader->maybeCallMethod(
99
                    $methods,
100
                    (string) $childNode->localName,
101
                    $childNode,
102
                    $group,
103
                    $childNode
104
                );
105
            }
106
        };
107
    }
108
}
109