AbstractNameIdentifierType   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 16
c 1
b 0
f 0
dl 0
loc 92
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 3 1
A __construct() 0 5 1
A getNameQualifier() 0 3 1
A getFormat() 0 3 1
A toXML() 0 14 3
A fromXML() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML11\XML\saml;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\SAML11\Type\SAMLAnyURIValue;
10
use SimpleSAML\SAML11\Type\SAMLStringValue;
11
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12
13
use function strval;
14
15
/**
16
 * SAML NameIdentifierType abstract data type.
17
 *
18
 * @package simplesamlphp/saml11
19
 */
20
abstract class AbstractNameIdentifierType extends AbstractSamlElement
21
{
22
    /**
23
     * Initialize a saml:NameIdentifierType from scratch
24
     *
25
     * @param \SimpleSAML\SAML11\Type\SAMLStringValue $value
26
     * @param \SimpleSAML\SAML11\Type\SAMLStringValue|null $NameQualifier
27
     * @param \SimpleSAML\SAML11\Type\SAMLAnyURIValue|null $Format
28
     */
29
    final public function __construct(
30
        protected SAMLStringValue $value,
31
        protected ?SAMLStringValue $NameQualifier = null,
32
        protected ?SAMLAnyURIValue $Format = null,
33
    ) {
34
    }
35
36
37
    /**
38
     * Collect the value of the value-property
39
     *
40
     * @return \SimpleSAML\SAML11\Type\SAMLStringValue
41
     */
42
    public function getValue(): SAMLStringValue
43
    {
44
        return $this->value;
45
    }
46
47
48
    /**
49
     * Collect the value of the Format-property
50
     *
51
     * @return \SimpleSAML\SAML11\Type\SAMLAnyURIValue|null
52
     */
53
    public function getFormat(): ?SAMLAnyURIValue
54
    {
55
        return $this->Format;
56
    }
57
58
59
    /**
60
     * Collect the value of the NameQualifier-property
61
     *
62
     * @return \SimpleSAML\SAML11\Type\SAMLStringValue|null
63
     */
64
    public function getNameQualifier(): ?SAMLStringValue
65
    {
66
        return $this->NameQualifier;
67
    }
68
69
70
    /**
71
     * Convert XML into an NameIdentifier
72
     *
73
     * @param \DOMElement $xml The XML element we should load
74
     * @return static
75
     *
76
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
77
     *   if the qualified name of the supplied element is wrong
78
     */
79
    public static function fromXML(DOMElement $xml): static
80
    {
81
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
82
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
83
84
        return new static(
85
            SAMLStringValue::fromString($xml->textContent),
86
            self::getOptionalAttribute($xml, 'NameQualifier', SAMLStringValue::class, null),
87
            self::getOptionalAttribute($xml, 'Format', SAMLAnyURIValue::class, null),
88
        );
89
    }
90
91
92
    /**
93
     * Convert this NameIdentifierType to XML.
94
     *
95
     * @param \DOMElement $parent The element we are converting to XML.
96
     * @return \DOMElement The XML element after adding the data corresponding to this NameIdentifierType.
97
     */
98
    public function toXML(?DOMElement $parent = null): DOMElement
99
    {
100
        $e = $this->instantiateParentElement($parent);
101
        $e->textContent = strval($this->getValue());
102
103
        if ($this->getNameQualifier() !== null) {
104
            $e->setAttribute('NameQualifier', strval($this->getNameQualifier()));
105
        }
106
107
        if ($this->getFormat() !== null) {
108
            $e->setAttribute('Format', strval($this->getFormat()));
109
        }
110
111
        return $e;
112
    }
113
}
114