Passed
Push — static-analysis ( 5a0c71...7ccf34 )
by SignpostMarv
03:20
created

ElementRef::loadElementRef()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3.3332

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 4
nop 3
dl 0
loc 18
ccs 8
cts 12
cp 0.6667
crap 3.3332
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace GoetasWebservices\XML\XSDReader\Schema\Element;
3
4
use DOMElement;
5
use GoetasWebservices\XML\XSDReader\Schema\Item;
6
use GoetasWebservices\XML\XSDReader\Schema\Schema;
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 135
    public function __construct(ElementDef $element)
37
    {
38 135
        parent::__construct($element->getSchema(), $element->getName());
39 135
        $this->wrapped = $element;
40 135
    }
41
42
    /**
43
     *
44
     * @return ElementDef
45
     */
46
    public function getReferencedElement()
47
    {
48
        return $this->wrapped;
49
    }
50
51
    /**
52
    * @return \GoetasWebservices\XML\XSDReader\Schema\Type\Type|null
53
    */
54
    public function getType()
55
    {
56
        return $this->wrapped->getType();
57
    }
58
59
    /**
60
    * @return int
61
    */
62
    public function getMin()
63
    {
64
        return $this->min;
65
    }
66
67
    /**
68
    * @param int $min
69
    *
70
    * @return $this
71
    */
72 135
    public function setMin($min)
73
    {
74 135
        $this->min = $min;
75 135
        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 135
    public function setMax($max)
92
    {
93 135
        $this->max = $max;
94 135
        return $this;
95
    }
96
97
    /**
98
    * @return bool
99
    */
100
    public function isQualified()
101
    {
102
        return $this->qualified;
103
    }
104
105
    /**
106
    * @param bool $qualified
107
    *
108
    * @return $this
109
    */
110
    public function setQualified($qualified)
111
    {
112
        $this->qualified = is_bool($qualified) ? $qualified : (boolean) $qualified;
113
        return $this;
114
    }
115
116
    /**
117
    * @return bool
118
    */
119
    public function isNil()
120
    {
121
        return $this->nil;
122
    }
123
124
    /**
125
    * @param bool $nil
126
    *
127
    * @return $this
128
    */
129
    public function setNil($nil)
130
    {
131
        $this->nil = is_bool($nil) ? $nil : (boolean) $nil;
132
        return $this;
133
    }
134
135
    /**
136
    * @return ElementRef
137
    */
138 135
    public static function loadElementRef(
139
        SchemaReader $reader,
0 ignored issues
show
Unused Code introduced by
The parameter $reader is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

139
        /** @scrutinizer ignore-unused */ SchemaReader $reader,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
140
        ElementDef $referenced,
141
        DOMElement $node
142
    ) {
143 135
        $ref = new ElementRef($referenced);
144 135
        $ref->setDoc(SchemaReader::getDocumentation($node));
145
146 135
        SchemaReader::maybeSetMax($ref, $node);
147 135
        SchemaReader::maybeSetMin($ref, $node);
148 135
        if ($node->hasAttribute("nillable")) {
149
            $ref->setNil($node->getAttribute("nillable") == "true");
150
        }
151 135
        if ($node->hasAttribute("form")) {
152
            $ref->setQualified($node->getAttribute("form") == "qualified");
153
        }
154
155 135
        return $ref;
156
    }
157
}
158