AbstractAttributeExtensibleURI   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

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

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\ExtendableAttributesTrait;
10
use SimpleSAML\XML\TypedTextContentTrait;
11
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12
use SimpleSAML\XMLSchema\Type\AnyURIValue;
13
use SimpleSAML\XMLSchema\XML\Constants\NS;
14
15
/**
16
 * An AbstractAttributeExtensibleURI element
17
 *
18
 * @package simplesamlphp/ws-security
19
 */
20
abstract class AbstractAttributeExtensibleURI extends AbstractFedElement
21
{
22
    use TypedTextContentTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\TypedTextContentTrait requires some properties which are not provided by SimpleSAML\WSSecurity\XM...tAttributeExtensibleURI: $localName, $namespaceURI
Loading history...
23
    use ExtendableAttributesTrait;
24
25
26
    /** @var string */
27
    public const TEXTCONTENT_TYPE = AnyURIValue::class;
28
29
    /** The namespace-attribute for the xs:anyAttribute element */
30
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
31
32
33
    /**
34
     * @param \SimpleSAML\XMLSchema\Type\AnyURIValue $content
35
     * @param \SimpleSAML\XML\Attribute[] $namespacedAttributes
36
     */
37
    final public function __construct(AnyURIValue $content, array $namespacedAttributes = [])
38
    {
39
        $this->setContent($content);
40
        $this->setAttributesNS($namespacedAttributes);
41
    }
42
43
44
    /**
45
     * Create a class from XML
46
     *
47
     * @param \DOMElement $xml
48
     * @return static
49
     */
50
    public static function fromXML(DOMElement $xml): static
51
    {
52
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
53
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
54
55
        return new static(
56
            AnyURIValue::fromString($xml->textContent),
57
            self::getAttributesNSFromXML($xml),
58
        );
59
    }
60
61
62
    /**
63
     * Create XML from this class
64
     *
65
     * @param \DOMElement|null $parent
66
     * @return \DOMElement
67
     */
68
    public function toXML(?DOMElement $parent = null): DOMElement
69
    {
70
        $e = $this->instantiateParentElement($parent);
71
        $e->textContent = $this->getContent()->getValue();
72
73
        foreach ($this->getAttributesNS() as $attr) {
74
            $attr->toXML($e);
75
        }
76
77
        return $e;
78
    }
79
}
80