Passed
Push — master ( 9d958a...532318 )
by Tim
02:50
created

Header   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
eloc 20
c 2
b 0
f 0
dl 0
loc 78
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SOAP12\XML;
6
7
use DOMElement;
8
use SimpleSAML\SOAP12\Assert\Assert;
9
use SimpleSAML\XML\ExtendableAttributesTrait;
10
use SimpleSAML\XML\ExtendableElementTrait;
11
use SimpleSAML\XML\SchemaValidatableElementInterface;
12
use SimpleSAML\XML\SchemaValidatableElementTrait;
13
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
14
use SimpleSAML\XMLSchema\XML\Constants\NS;
15
16
/**
17
 * Class representing a env:Header element.
18
 *
19
 * @package simplesaml/xml-soap
20
 */
21
final class Header extends AbstractSoapElement implements SchemaValidatableElementInterface
22
{
23
    use ExtendableAttributesTrait;
24
    use ExtendableElementTrait;
25
    use SchemaValidatableElementTrait;
26
27
28
    /** The namespace-attribute for the xs:any element */
29
    public const string XS_ANY_ELT_NAMESPACE = NS::ANY;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting '=' on line 29 at column 24
Loading history...
30
31
    /** The namespace-attribute for the xs:anyAttribute element */
32
    public const string XS_ANY_ATTR_NAMESPACE = NS::OTHER;
33
34
35
    /**
36
     * Initialize a env:Header
37
     *
38
     * @param list<\SimpleSAML\XML\SerializableElementInterface> $children
39
     * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
40
     */
41
    public function __construct(array $children = [], array $namespacedAttributes = [])
42
    {
43
        $this->setElements($children);
44
        $this->setAttributesNS($namespacedAttributes);
45
    }
46
47
48
    /**
49
     * Test if an object, at the state it's in, would produce an empty XML-element
50
     */
51
    public function isEmptyElement(): bool
52
    {
53
        return empty($this->elements) && empty($this->namespacedAttributes);
54
    }
55
56
57
    /*
58
     * Convert XML into an Header element
59
     *
60
     * @param \DOMElement $xml The XML element we should load
61
     *
62
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
63
     *   If the qualified name of the supplied element is wrong
64
     */
65
    public static function fromXML(DOMElement $xml): static
66
    {
67
        Assert::same($xml->localName, 'Header', InvalidDOMElementException::class);
68
        Assert::same($xml->namespaceURI, Header::NS, InvalidDOMElementException::class);
69
70
        return new static(
71
            self::getChildElementsFromXML($xml),
72
            self::getAttributesNSFromXML($xml),
73
        );
74
    }
75
76
77
    /**
78
     * Convert this Header to XML.
79
     *
80
     * @param \DOMElement|null $parent The element we should add this header to.
81
     */
82
    public function toXML(?DOMElement $parent = null): DOMElement
83
    {
84
        $e = $this->instantiateParentElement($parent);
85
86
        foreach ($this->getAttributesNS() as $attr) {
87
            $attr->toXML($e);
88
        }
89
90
        foreach ($this->getElements() as $child) {
91
            $child->toXML($e);
92
        }
93
94
        return $e;
95
    }
96
}
97