Passed
Pull Request — master (#18)
by SignpostMarv
03:22
created

Attribute   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 174
Duplicated Lines 0 %

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 174
ccs 35
cts 45
cp 0.7778
rs 10
wmc 16

12 Methods

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