ReferenceProperties::toXML()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 11
rs 10
c 1
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\wsa_200408;
6
7
use DOMElement;
8
use SimpleSAML\WSSecurity\Assert\Assert;
9
use SimpleSAML\XML\ExtendableElementTrait;
10
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
11
use SimpleSAML\XMLSchema\XML\Constants\NS;
12
13
/**
14
 * Class representing a wsa:ReferenceProperties element.
15
 *
16
 * @package simplesamlphp/ws-security
17
 */
18
final class ReferenceProperties extends AbstractWsaElement
19
{
20
    use ExtendableElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\ExtendableElementTrait requires some properties which are not provided by SimpleSAML\WSSecurity\XM...408\ReferenceProperties: $namespaceURI, $localName, $childNodes
Loading history...
21
22
23
    /** The namespace-attribute for the xs:any element */
24
    public const XS_ANY_ELT_NAMESPACE = NS::ANY;
25
26
27
    /**
28
     * Initialize a wsa:ReferenceProperties
29
     *
30
     * @param \SimpleSAML\XML\SerializableElementInterface[] $children
31
     */
32
    public function __construct(array $children = [])
33
    {
34
        $this->setElements($children);
35
    }
36
37
38
    /**
39
     * Test if an object, at the state it's in, would produce an empty XML-element
40
     *
41
     * @return bool
42
     */
43
    public function isEmptyElement(): bool
44
    {
45
        return empty($this->elements);
46
    }
47
48
49
    /*
50
     * Convert XML into an ReferenceProperties element
51
     *
52
     * @param \DOMElement $xml The XML element we should load
53
     * @return static
54
     *
55
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
56
     *   If the qualified name of the supplied element is wrong
57
     */
58
    public static function fromXML(DOMElement $xml): static
59
    {
60
        Assert::same($xml->localName, 'ReferenceProperties', InvalidDOMElementException::class);
61
        Assert::same($xml->namespaceURI, ReferenceProperties::NS, InvalidDOMElementException::class);
62
63
        return new static(
64
            self::getChildElementsFromXML($xml),
65
        );
66
    }
67
68
69
    /**
70
     * Convert this ReferenceProperties to XML.
71
     *
72
     * @param \DOMElement|null $parent The element we should add this ReferenceProperties to.
73
     * @return \DOMElement This Header-element.
74
     */
75
    public function toXML(?DOMElement $parent = null): DOMElement
76
    {
77
        $e = $this->instantiateParentElement($parent);
78
79
        foreach ($this->getElements() as $child) {
80
            if (!$child->isEmptyElement()) {
81
                $child->toXML($e);
82
            }
83
        }
84
85
        return $e;
86
    }
87
}
88