Passed
Push — static-analysis ( 661417...be3dd0 )
by SignpostMarv
02:22
created

ElementRef   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 60%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 49
ccs 12
cts 20
cp 0.6
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getReferencedElement() 0 3 1
A loadElementRef() 0 17 3
A getType() 0 3 1
A __construct() 0 4 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 AbstractElementSingle
10
{
11
    /**
12
     * @var ElementDef
13
     */
14
    protected $wrapped;
15
16 45
    public function __construct(ElementDef $element)
17
    {
18 45
        parent::__construct($element->getSchema(), $element->getName());
19 45
        $this->wrapped = $element;
20 45
    }
21
22
    /**
23
     * @return ElementDef
24
     */
25
    public function getReferencedElement()
26
    {
27
        return $this->wrapped;
28
    }
29
30
    /**
31
     * @return \GoetasWebservices\XML\XSDReader\Schema\Type\Type|null
32
     */
33
    public function getType()
34
    {
35
        return $this->wrapped->getType();
36
    }
37
38
    /**
39
     * @return ElementRef
40
     */
41 45
    public static function loadElementRef(
42
        ElementDef $referenced,
43
        DOMElement $node
44
    ) {
45 45
        $ref = new self($referenced);
46 45
        $ref->setDoc(SchemaReader::getDocumentation($node));
47
48 45
        SchemaReader::maybeSetMax($ref, $node);
49 45
        SchemaReader::maybeSetMin($ref, $node);
50 45
        if ($node->hasAttribute('nillable')) {
51
            $ref->setNil($node->getAttribute('nillable') == 'true');
52
        }
53 45
        if ($node->hasAttribute('form')) {
54
            $ref->setQualified($node->getAttribute('form') == 'qualified');
55
        }
56
57 45
        return $ref;
58
    }
59
}
60