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

ElementRef   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 149
Duplicated Lines 0 %

Test Coverage

Coverage 45%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 149
ccs 18
cts 40
cp 0.45
rs 10
wmc 16

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getMax() 0 3 1
A getReferencedElement() 0 3 1
A setQualified() 0 5 2
A setMin() 0 5 1
A loadElementRef() 0 17 3
A getType() 0 3 1
A setNil() 0 5 2
A isQualified() 0 3 1
A getMin() 0 3 1
A setMax() 0 5 1
A isNil() 0 3 1
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\SchemaReader;
8
9
class ElementRef extends Item implements ElementSingle
10
{
11
    /**
12
     * @var ElementDef
13
     */
14
    protected $wrapped;
15
16
    /**
17
     * @var int
18
     */
19
    protected $min = 1;
20
21
    /**
22
     * @var int
23
     */
24
    protected $max = 1;
25
26
    /**
27
     * @var bool
28
     */
29
    protected $qualified = true;
30
31
    /**
32
     * @var bool
33
     */
34
    protected $nil = false;
35
36 45
    public function __construct(ElementDef $element)
37
    {
38 45
        parent::__construct($element->getSchema(), $element->getName());
39 45
        $this->wrapped = $element;
40 45
    }
41
42
    /**
43
     * @return ElementDef
44
     */
45
    public function getReferencedElement()
46
    {
47
        return $this->wrapped;
48
    }
49
50
    /**
51
     * @return \GoetasWebservices\XML\XSDReader\Schema\Type\Type|null
52
     */
53
    public function getType()
54
    {
55
        return $this->wrapped->getType();
56
    }
57
58
    /**
59
     * @return int
60
     */
61
    public function getMin()
62
    {
63
        return $this->min;
64
    }
65
66
    /**
67
     * @param int $min
68
     *
69
     * @return $this
70
     */
71 45
    public function setMin($min)
72
    {
73 45
        $this->min = $min;
74
75 45
        return $this;
76
    }
77
78
    /**
79
     * @return int
80
     */
81
    public function getMax()
82
    {
83
        return $this->max;
84
    }
85
86
    /**
87
     * @param int $max
88
     *
89
     * @return $this
90
     */
91 45
    public function setMax($max)
92
    {
93 45
        $this->max = $max;
94
95 45
        return $this;
96
    }
97
98
    /**
99
     * @return bool
100
     */
101
    public function isQualified()
102
    {
103
        return $this->qualified;
104
    }
105
106
    /**
107
     * @param bool $qualified
108
     *
109
     * @return $this
110
     */
111
    public function setQualified($qualified)
112
    {
113
        $this->qualified = is_bool($qualified) ? $qualified : (bool) $qualified;
114
115
        return $this;
116
    }
117
118
    /**
119
     * @return bool
120
     */
121
    public function isNil()
122
    {
123
        return $this->nil;
124
    }
125
126
    /**
127
     * @param bool $nil
128
     *
129
     * @return $this
130
     */
131
    public function setNil($nil)
132
    {
133
        $this->nil = is_bool($nil) ? $nil : (bool) $nil;
134
135
        return $this;
136
    }
137
138
    /**
139
     * @return ElementRef
140
     */
141 45
    public static function loadElementRef(
142
        ElementDef $referenced,
143
        DOMElement $node
144
    ) {
145 45
        $ref = new self($referenced);
146 45
        $ref->setDoc(SchemaReader::getDocumentation($node));
147
148 45
        SchemaReader::maybeSetMax($ref, $node);
149 45
        SchemaReader::maybeSetMin($ref, $node);
150 45
        if ($node->hasAttribute('nillable')) {
151
            $ref->setNil($node->getAttribute('nillable') == 'true');
152
        }
153 45
        if ($node->hasAttribute('form')) {
154
            $ref->setQualified($node->getAttribute('form') == 'qualified');
155
        }
156
157 45
        return $ref;
158
    }
159
}
160