Completed
Pull Request — master (#18)
by SignpostMarv
02:40
created

ElementRef::loadElementRef()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 17
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 2
dl 0
loc 17
ccs 8
cts 12
cp 0.6667
crap 3.3332
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace GoetasWebservices\XML\XSDReader\Schema\Element;
4
5
use DOMElement;
6
use GoetasWebservices\XML\XSDReader\SchemaReader;
7
8
class ElementRef extends AbstractElementSingle
9
{
10
    /**
11
     * @var ElementDef
12
     */
13
    protected $wrapped;
14
15 45
    public function __construct(ElementDef $element)
16
    {
17 45
        parent::__construct($element->getSchema(), $element->getName());
18 45
        $this->wrapped = $element;
19 45
    }
20
21
    /**
22
     * @return ElementDef
23
     */
24
    public function getReferencedElement()
25
    {
26
        return $this->wrapped;
27
    }
28
29
    /**
30
     * @return \GoetasWebservices\XML\XSDReader\Schema\Type\Type|null
31
     */
32
    public function getType()
33
    {
34
        return $this->wrapped->getType();
35
    }
36
37
    /**
38
     * @return ElementRef
39
     */
40 45
    public static function loadElementRef(
41
        ElementDef $referenced,
42
        DOMElement $node
43
    ) {
44 45
        $ref = new self($referenced);
45 45
        $ref->setDoc(SchemaReader::getDocumentation($node));
46
47 45
        SchemaReader::maybeSetMax($ref, $node);
48 45
        SchemaReader::maybeSetMin($ref, $node);
49 45
        if ($node->hasAttribute('nillable')) {
50
            $ref->setNil($node->getAttribute('nillable') == 'true');
51
        }
52 45
        if ($node->hasAttribute('form')) {
53
            $ref->setQualified($node->getAttribute('form') == 'qualified');
54
        }
55
56 45
        return $ref;
57
    }
58
}
59