InclusiveNamespaces   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 8
c 2
b 0
f 0
dl 0
loc 56
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPrefixes() 0 3 1
A toXML() 0 9 2
A __construct() 0 3 1
A fromXML() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\ec;
6
7
use DOMElement;
8
use SimpleSAML\XML\SchemaValidatableElementInterface;
9
use SimpleSAML\XML\SchemaValidatableElementTrait;
10
use SimpleSAML\XMLSchema\Type\NMTokensValue;
11
12
use function strval;
13
14
/**
15
 * Class implementing InclusiveNamespaces
16
 *
17
 * @package simplesamlphp/xml-security
18
 */
19
class InclusiveNamespaces extends AbstractEcElement implements SchemaValidatableElementInterface
20
{
21
    use SchemaValidatableElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\SchemaValidatableElementTrait requires some properties which are not provided by SimpleSAML\XMLSecurity\XML\ec\InclusiveNamespaces: $message, $line
Loading history...
22
23
24
    /**
25
     * Initialize the InclusiveNamespaces element.
26
     *
27
     * @param \SimpleSAML\XMLSchema\Type\NMTokensValue|null $prefixes
28
     */
29
    final public function __construct(
30
        protected ?NMTokensValue $prefixes,
31
    ) {
32
    }
33
34
35
    /**
36
     * Get the prefixes specified by this element.
37
     *
38
     * @return \SimpleSAML\XMLSchema\Type\NMTokensValue|null
39
     */
40
    public function getPrefixes(): ?NMTokensValue
41
    {
42
        return $this->prefixes;
43
    }
44
45
46
    /**
47
     * Convert XML into an InclusiveNamespaces element.
48
     *
49
     * @param \DOMElement $xml The XML element we should load.
50
     * @return static
51
     */
52
    public static function fromXML(DOMElement $xml): static
53
    {
54
        return new static(
55
            self::getOptionalAttribute($xml, 'PrefixList', NMTokensValue::class, null),
56
        );
57
    }
58
59
60
    /**
61
     * Convert this InclusiveNamespaces to XML.
62
     *
63
     * @param \DOMElement|null $parent The element we should append this InclusiveNamespaces to.
64
     * @return \DOMElement
65
     */
66
    public function toXML(?DOMElement $parent = null): DOMElement
67
    {
68
        $e = $this->instantiateParentElement($parent);
69
70
        if ($this->getPrefixes() !== null) {
71
            $e->setAttribute('PrefixList', strval($this->getPrefixes()));
72
        }
73
74
        return $e;
75
    }
76
}
77