Completed
Push — master ( f72cfb...4ef12f )
by Tim
21s queued 18s
created

AbstractSimpleType   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 83
rs 10
c 1
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getFinal() 0 3 1
A __construct() 0 11 1
A isEmptyElement() 0 3 1
A toXML() 0 15 3
A getName() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSchema\XML\xs;
6
7
use DOMElement;
8
use SimpleSAML\XMLSchema\Type\Builtin\{IDValue, NCNameValue};
9
use SimpleSAML\XMLSchema\Type\SimpleDerivationSetValue;
10
use SimpleSAML\XMLSchema\XML\xs\SimpleDerivationTrait;
11
12
use function strval;
13
14
/**
15
 * Abstract class representing the abstract simpleType.
16
 *
17
 * @package simplesamlphp/xml-common
18
 */
19
abstract class AbstractSimpleType extends AbstractAnnotated
20
{
21
    use SimpleDerivationTrait;
22
23
24
    /**
25
     * SimpleType constructor
26
     *
27
     * @param \SimpleSAML\XMLSchema\XML\xs\SimpleDerivationInterface $derivation
28
     * @param \SimpleSAML\XMLSchema\Type\Builtin\NCNameValue $name
29
     * @param \SimpleSAML\XMLSchema\Type\SimpleDerivationSetValue $final
30
     * @param \SimpleSAML\XMLSchema\XML\xs\Annotation|null $annotation
31
     * @param \SimpleSAML\XMLSchema\Type\Builtin\IDValue|null $id
32
     * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
33
     */
34
    public function __construct(
35
        SimpleDerivationInterface $derivation,
36
        protected ?NCNameValue $name = null,
37
        protected ?SimpleDerivationSetValue $final = null,
38
        ?Annotation $annotation = null,
39
        ?IDValue $id = null,
40
        array $namespacedAttributes = [],
41
    ) {
42
        parent::__construct($annotation, $id, $namespacedAttributes);
43
44
        $this->setDerivation($derivation);
45
    }
46
47
48
    /**
49
     * Collect the value of the final-property
50
     *
51
     * @return \SimpleSAML\XMLSchema\Type\SimpleDerivationSetValue|null
52
     */
53
    public function getFinal(): ?SimpleDerivationSetValue
54
    {
55
        return $this->final;
56
    }
57
58
59
    /**
60
     * Collect the value of the name-property
61
     *
62
     * @return \SimpleSAML\XMLSchema\Type\Builtin\NCNameValue|null
63
     */
64
    public function getName(): ?NCNameValue
65
    {
66
        return $this->name;
67
    }
68
69
70
    /**
71
     * Test if an object, at the state it's in, would produce an empty XML-element
72
     *
73
     * @return bool
74
     */
75
    public function isEmptyElement(): bool
76
    {
77
        return false;
78
    }
79
80
81
    /**
82
     * Add this SimpleType to an XML element.
83
     *
84
     * @param \DOMElement|null $parent The element we should append this SimpleType to.
85
     * @return \DOMElement
86
     */
87
    public function toXML(?DOMElement $parent = null): DOMElement
88
    {
89
        $e = parent::toXML($parent);
90
91
        if ($this->getFinal() !== null) {
92
            $e->setAttribute('final', strval($this->getFinal()));
93
        }
94
95
        if ($this->getName() !== null) {
96
            $e->setAttribute('name', strval($this->getName()));
97
        }
98
99
        $this->getDerivation()->toXML($e);
100
101
        return $e;
102
    }
103
}
104