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

Detail   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Importance

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