Passed
Push — static-analysis ( 3fedee...5a0c71 )
by SignpostMarv
03:09
created

Attribute::getAttributeFromAttributeOrRef()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 4
dl 0
loc 19
ccs 6
cts 6
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace GoetasWebservices\XML\XSDReader\Schema\Attribute;
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 Attribute extends Item implements AttributeSingle
10
{
11
    /**
12
    * @var static|null
13
    */
14
    protected $fixed;
15
16
    /**
17
    * @var static|null
18
    */
19
    protected $default;
20
21
    /**
22
    * @var bool
23
    */
24
    protected $qualified = true;
25
26
    /**
27
    * @var bool
28
    */
29
    protected $nil = false;
30
31
    /**
32
    * @var string
33
    */
34
    protected $use = self::USE_OPTIONAL;
35
36
    /**
37
    * @return static|null
38
    */
39
    public function getFixed()
40
    {
41
        return $this->fixed;
42
    }
43
44
    /**
45
    * @param static $fixed
46
    *
47
    * @return $this
48
    */
49
    public function setFixed($fixed)
50
    {
51
        $this->fixed = $fixed;
52
        return $this;
53
    }
54
55
    /**
56
    * @return static|null
57
    */
58
    public function getDefault()
59
    {
60
        return $this->default;
61
    }
62
63
    /**
64
    * @param static $default
65
    *
66
    * @return $this
67
    */
68
    public function setDefault($default)
69
    {
70
        $this->default = $default;
71
        return $this;
72
    }
73
74
    /**
75
    * @return bool
76
    */
77 3
    public function isQualified()
78
    {
79 3
        return $this->qualified;
80
    }
81
82
    /**
83
    * @param bool $qualified
84
    *
85
    * @return $this
86
    */
87 3
    public function setQualified($qualified)
88
    {
89 3
        $this->qualified = $qualified;
90 3
        return $this;
91
    }
92
93
    /**
94
    * @return bool
95
    */
96 3
    public function isNil()
97
    {
98 3
        return $this->nil;
99
    }
100
101
    /**
102
    * @param bool $nil
103
    *
104
    * @return $this
105
    */
106 3
    public function setNil($nil)
107
    {
108 3
        $this->nil = $nil;
109 3
        return $this;
110
    }
111
112
    /**
113
    * @return string
114
    */
115 3
    public function getUse()
116
    {
117 3
        return $this->use;
118
    }
119
120
    /**
121
    * @param string $use
122
    *
123
    * @return $this
124
    */
125 135
    public function setUse($use)
126
    {
127 135
        $this->use = $use;
128 135
        return $this;
129
    }
130
131
    /**
132
    * @return Attribute
133
    */
134 135
    public static function loadAttribute(
135
        SchemaReader $schemaReader,
136
        Schema $schema,
137
        DOMElement $node
138
    ) {
139 135
        $attribute = new Attribute($schema, $node->getAttribute("name"));
140 135
        $attribute->setDoc(SchemaReader::getDocumentation($node));
141 135
        $schemaReader->fillItem($attribute, $node);
142
143 135
        if ($node->hasAttribute("nillable")) {
144 3
            $attribute->setNil($node->getAttribute("nillable") == "true");
145 1
        }
146 135
        if ($node->hasAttribute("form")) {
147 3
            $attribute->setQualified($node->getAttribute("form") == "qualified");
148 1
        }
149 135
        if ($node->hasAttribute("use")) {
150 135
            $attribute->setUse($node->getAttribute("use"));
151 45
        }
152 135
        return $attribute;
153
    }
154
155
    /**
156
    * @return AttributeItem
157
    */
158 135
    public static function getAttributeFromAttributeOrRef(
159
        SchemaReader $schemaReader,
160
        DOMElement $childNode,
161
        Schema $schema,
162
        DOMElement $node
163
    ) {
164 135
        if ($childNode->hasAttribute("ref")) {
165
            /**
166
            * @var AttributeItem $attribute
167
            */
168 135
            $attribute = $schemaReader->findSomething('findAttribute', $schema, $node, $childNode->getAttribute("ref"));
169 45
        } else {
170
            /**
171
            * @var Attribute $attribute
172
            */
173 135
            $attribute = Attribute::loadAttribute($schemaReader, $schema, $childNode);
174
        }
175
176 135
        return $attribute;
177
    }
178
}
179