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

Detail::isEmptyElement()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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