Passed
Push — master ( 8413b2...00f101 )
by Tim
02:19
created

AbstractFacet   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 3 1
A getFixed() 0 3 1
A toXML() 0 11 2
A __construct() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSchema\XML;
6
7
use DOMElement;
8
use SimpleSAML\XMLSchema\Type\{BooleanValue, IDValue};
9
use SimpleSAML\XMLSchema\Type\Interface\ValueTypeInterface;
10
11
use function strval;
12
13
/**
14
 * Abstract class representing the facet-type.
15
 *
16
 * @package simplesamlphp/xml-common
17
 */
18
abstract class AbstractFacet extends AbstractAnnotated
19
{
20
    /**
21
     * Facet constructor
22
     *
23
     * @param \SimpleSAML\XMLSchema\Type\Interface\ValueTypeInterface $value
24
     * @param \SimpleSAML\XMLSchema\Type\BooleanValue $fixed
25
     * @param \SimpleSAML\XMLSchema\XML\Annotation|null $annotation
26
     * @param \SimpleSAML\XMLSchema\Type\IDValue|null $id
27
     * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
28
     */
29
    public function __construct(
30
        protected ValueTypeInterface $value,
31
        protected ?BooleanValue $fixed = null,
32
        ?Annotation $annotation = null,
33
        ?IDValue $id = null,
34
        array $namespacedAttributes = [],
35
    ) {
36
        parent::__construct($annotation, $id, $namespacedAttributes);
37
    }
38
39
40
    /**
41
     * Collect the value of the value-property
42
     *
43
     * @return \SimpleSAML\XMLSchema\Type\Interface\ValueTypeInterface
44
     */
45
    public function getValue(): ValueTypeInterface
46
    {
47
        return $this->value;
48
    }
49
50
51
    /**
52
     * Collect the value of the fixed-property
53
     *
54
     * @return \SimpleSAML\XMLSchema\Type\BooleanValue|null
55
     */
56
    public function getFixed(): ?BooleanValue
57
    {
58
        return $this->fixed;
59
    }
60
61
62
    /**
63
     * Add this Facet to an XML element.
64
     *
65
     * @param \DOMElement|null $parent The element we should append this facet to.
66
     * @return \DOMElement
67
     */
68
    public function toXML(?DOMElement $parent = null): DOMElement
69
    {
70
        $e = parent::toXML($parent);
71
72
        $e->setAttribute('value', strval($this->getValue()));
73
74
        if ($this->getFixed() !== null) {
75
            $e->setAttribute('fixed', strval($this->getFixed()));
76
        }
77
78
        return $e;
79
    }
80
}
81