AbstractIssuerNameType   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 15
dl 0
loc 69
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A toXML() 0 10 2
A fromXML() 0 8 1
A getUri() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\fed;
6
7
use DOMElement;
8
use SimpleSAML\WSSecurity\Assert\Assert;
9
use SimpleSAML\XML\ExtendableAttributesTrait;
10
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
11
use SimpleSAML\XMLSchema\Type\AnyURIValue;
12
use SimpleSAML\XMLSchema\XML\Constants\NS;
13
14
/**
15
 * Class defining the IssuerNameType element
16
 *
17
 * @package simplesamlphp/ws-security
18
 */
19
abstract class AbstractIssuerNameType extends AbstractFedElement
20
{
21
    use ExtendableAttributesTrait;
22
23
24
    /** The namespace-attribute for the xs:anyAttribute element */
25
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
26
27
28
    /**
29
     * AbstractIssuerNameType constructor
30
     *
31
     * @param \SimpleSAML\XMLSchema\Type\AnyURIValue $Uri
32
     * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
33
     */
34
    final public function __construct(
35
        protected AnyURIValue $Uri,
36
        array $namespacedAttributes = [],
37
    ) {
38
        $this->setAttributesNS($namespacedAttributes);
39
    }
40
41
42
    /**
43
     * @return \SimpleSAML\XMLSchema\Type\AnyURIValue
44
     */
45
    public function getUri(): AnyURIValue
46
    {
47
        return $this->Uri;
48
    }
49
50
51
    /**
52
     * Create an instance of this object from its XML representation.
53
     *
54
     * @param \DOMElement $xml
55
     * @return static
56
     *
57
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
58
     *   if the qualified name of the supplied element is wrong
59
     */
60
    public static function fromXML(DOMElement $xml): static
61
    {
62
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
63
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
64
65
        return new static(
66
            self::getAttribute($xml, 'Uri', AnyURIValue::class),
67
            self::getAttributesNSFromXML($xml),
68
        );
69
    }
70
71
72
    /**
73
     * Add this IssuerNameType to an XML element.
74
     *
75
     * @param \DOMElement|null $parent The element we should append this issuer name to.
76
     * @return \DOMElement
77
     */
78
    public function toXML(?DOMElement $parent = null): DOMElement
79
    {
80
        $e = parent::instantiateParentElement($parent);
81
        $e->setAttribute('Uri', $this->getUri()->getValue());
82
83
        foreach ($this->getAttributesNS() as $attr) {
84
            $attr->toXML($e);
85
        }
86
87
        return $e;
88
    }
89
}
90