MetadataReference::fromXML()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 7
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\wsx;
6
7
use DOMElement;
8
use SimpleSAML\WSSecurity\Assert\Assert;
9
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10
use SimpleSAML\XML\Exception\MissingElementException;
11
use SimpleSAML\XML\ExtendableElementTrait;
12
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
13
use SimpleSAML\XML\XsNamespace as NS;
14
15
/**
16
 * Class defining the MetadataReference element
17
 *
18
 * @package simplesamlphp/ws-security
19
 */
20
final class MetadataReference extends AbstractWsxElement implements SchemaValidatableElementInterface
21
{
22
    use ExtendableElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\ExtendableElementTrait requires some properties which are not provided by SimpleSAML\WSSecurity\XML\wsx\MetadataReference: $namespaceURI, $localName, $childNodes
Loading history...
23
    use SchemaValidatableElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\SchemaValidatableElementTrait requires some properties which are not provided by SimpleSAML\WSSecurity\XML\wsx\MetadataReference: $message, $line
Loading history...
24
25
    /** The namespace-attribute for the xs:any element */
26
    public const XS_ANY_ELT_NAMESPACE = NS::OTHER;
27
28
29
    /**
30
     * MetadataReference constructor
31
     *
32
     * @param \SimpleSAML\XML\SerializableElementInterface[] $children
33
     */
34
    final public function __construct(
35
        array $children = [],
36
    ) {
37
        Assert::minCount($children, 1, MissingElementException::class);
38
        $this->setElements($children);
39
    }
40
41
42
    /**
43
     * Create an instance of this object from its XML representation.
44
     *
45
     * @param \DOMElement $xml
46
     * @return static
47
     *
48
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
49
     *   if the qualified name of the supplied element is wrong
50
     */
51
    public static function fromXML(DOMElement $xml): static
52
    {
53
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
54
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
55
56
        return new static(
57
            self::getChildElementsFromXML($xml),
58
        );
59
    }
60
61
62
    /**
63
     * Add this MetadataReference to an XML element.
64
     *
65
     * @param \DOMElement|null $parent The element we should append this MetadataReference to.
66
     * @return \DOMElement
67
     */
68
    public function toXML(?DOMElement $parent = null): DOMElement
69
    {
70
        $e = parent::instantiateParentElement($parent);
71
72
        foreach ($this->getElements() as $child) {
73
            if (!$child->isEmptyElement()) {
74
                $child->toXML($e);
75
            }
76
        }
77
78
        return $e;
79
    }
80
}
81