Test Failed
Pull Request — master (#18)
by SignpostMarv
03:33
created

Element::getMin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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