AbstractAttributeExtensibleURI   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fromXML() 0 8 1
A toXML() 0 10 2
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\Exception\InvalidDOMElementException;
10
use SimpleSAML\XML\ExtendableAttributesTrait;
11
use SimpleSAML\XML\URIElementTrait;
12
use SimpleSAML\XML\XsNamespace as NS;
13
14
/**
15
 * An AbstractAttributeExtensibleURI element
16
 *
17
 * @package simplesamlphp/ws-security
18
 */
19
abstract class AbstractAttributeExtensibleURI extends AbstractFedElement
20
{
21
    use URIElementTrait;
22
    use ExtendableAttributesTrait;
23
24
    /** The namespace-attribute for the xs:anyAttribute element */
25
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
26
27
28
    /**
29
     * @param string $content
30
     * @param \SimpleSAML\XML\Attribute[] $namespacedAttributes
31
     */
32
    final public function __construct(string $content, array $namespacedAttributes = [])
33
    {
34
        $this->setContent($content);
35
        $this->setAttributesNS($namespacedAttributes);
36
    }
37
38
39
    /**
40
     * Create a class from XML
41
     *
42
     * @param \DOMElement $xml
43
     * @return static
44
     */
45
    public static function fromXML(DOMElement $xml): static
46
    {
47
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
48
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
49
50
        return new static(
51
            $xml->textContent,
52
            self::getAttributesNSFromXML($xml),
53
        );
54
    }
55
56
57
    /**
58
     * Create XML from this class
59
     *
60
     * @param \DOMElement|null $parent
61
     * @return \DOMElement
62
     */
63
    public function toXML(?DOMElement $parent = null): DOMElement
64
    {
65
        $e = $this->instantiateParentElement($parent);
66
        $e->textContent = $this->getContent();
67
68
        foreach ($this->getAttributesNS() as $attr) {
69
            $attr->toXML($e);
70
        }
71
72
        return $e;
73
    }
74
}
75