Passed
Push — static-analysis ( d5a974...87b144 )
by SignpostMarv
03:37
created

Group::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 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
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 135
    public function __construct(Schema $schema, $name)
29
    {
30 135
        $this->schema = $schema;
31 135
        $this->name = $name;
32 135
    }
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 135
    public function setDoc($doc)
48
    {
49 135
        $this->doc = $doc;
50 135
        return $this;
51
    }
52
53
    /**
54
    * @return Schema
55
    */
56 135
    public function getSchema()
57
    {
58 135
        return $this->schema;
59
    }
60
61
    /**
62
    * @return \Closure
63
    */
64 135
    public static function loadGroup(
65
        SchemaReader $reader,
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 90
        static $methods = [
91
            'sequence' => 'loadSequence',
92
            'choice' => 'loadSequence',
93
            'all' => 'loadSequence',
94 45
        ];
95
96 135
        return function () use ($reader, $group, $node, $methods) {
97 135
            foreach ($node->childNodes as $childNode) {
98 135
                $reader->maybeCallMethod(
99 135
                    $methods,
100 135
                    (string) $childNode->localName,
101 135
                    $childNode,
102 135
                    $group,
103 90
                    $childNode
104 45
                );
105 45
            }
106 135
        };
107
    }
108
}
109