Completed
Pull Request — master (#18)
by SignpostMarv
03:00
created

Element   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 133
ccs 38
cts 38
cp 1
rs 10
wmc 14

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getMin() 0 3 1
A getMax() 0 3 1
A isQualified() 0 3 1
B loadElement() 0 28 4
A setMin() 0 5 1
A setMax() 0 5 1
A setNil() 0 5 2
A isNil() 0 3 1
A setQualified() 0 5 2
1
<?php
2
3
namespace GoetasWebservices\XML\XSDReader\Schema\Element;
4
5
use DOMElement;
6
use GoetasWebservices\XML\XSDReader\Schema\Item;
7
use GoetasWebservices\XML\XSDReader\Schema\Schema;
8
use GoetasWebservices\XML\XSDReader\SchemaReader;
9
10
class Element extends Item implements ElementItem, ElementSingle
11
{
12
    /**
13
     * @var int
14
     */
15
    protected $min = 1;
16
17
    /**
18
     * @var int
19
     */
20
    protected $max = 1;
21
22
    /**
23
     * @var bool
24
     */
25
    protected $qualified = false;
26
27
    /**
28
     * @var bool
29
     */
30
    protected $nil = false;
31
32
    /**
33
     * @return int
34
     */
35 2
    public function getMin()
36
    {
37 2
        return $this->min;
38
    }
39
40
    /**
41
     * @param int $min
42
     *
43
     * @return $this
44
     */
45 45
    public function setMin($min)
46
    {
47 45
        $this->min = $min;
48
49 45
        return $this;
50
    }
51
52
    /**
53
     * @return int
54
     */
55 4
    public function getMax()
56
    {
57 4
        return $this->max;
58
    }
59
60
    /**
61
     * @param int $max
62
     *
63
     * @return $this
64
     */
65 45
    public function setMax($max)
66
    {
67 45
        $this->max = $max;
68
69 45
        return $this;
70
    }
71
72
    /**
73
     * @return bool
74
     */
75 1
    public function isQualified()
76
    {
77 1
        return $this->qualified;
78
    }
79
80
    /**
81
     * @param bool $qualified
82
     *
83
     * @return $this
84
     */
85 3
    public function setQualified($qualified)
86
    {
87 3
        $this->qualified = is_bool($qualified) ? $qualified : (bool) $qualified;
88
89 3
        return $this;
90
    }
91
92
    /**
93
     * @return bool
94
     */
95 1
    public function isNil()
96
    {
97 1
        return $this->nil;
98
    }
99
100
    /**
101
     * @param bool $nil
102
     *
103
     * @return $this
104
     */
105 3
    public function setNil($nil)
106
    {
107 3
        $this->nil = is_bool($nil) ? $nil : (bool) $nil;
108
109 3
        return $this;
110
    }
111
112
    /**
113
     * @return Element
114
     */
115 45
    public static function loadElement(
116
        SchemaReader $reader,
117
        Schema $schema,
118
        DOMElement $node
119
    ) {
120 45
        $element = new self($schema, $node->getAttribute('name'));
121 45
        $element->setDoc(SchemaReader::getDocumentation($node));
122
123 45
        $reader->fillItem($element, $node);
124
125 45
        SchemaReader::maybeSetMax($element, $node);
126 45
        SchemaReader::maybeSetMin($element, $node);
127
128 45
        $xp = new \DOMXPath($node->ownerDocument);
129 45
        $xp->registerNamespace('xs', 'http://www.w3.org/2001/XMLSchema');
130
131 45
        if ($xp->query('ancestor::xs:choice', $node)->length) {
132 45
            $element->setMin(0);
133 45
        }
134
135 45
        if ($node->hasAttribute('nillable')) {
136 3
            $element->setNil($node->getAttribute('nillable') == 'true');
137 3
        }
138 45
        if ($node->hasAttribute('form')) {
139 3
            $element->setQualified($node->getAttribute('form') == 'qualified');
140 3
        }
141
142 45
        return $element;
143
    }
144
}
145