Detail::toXML()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 4
nop 1
dl 0
loc 14
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SOAP\XML\env_200106;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\AbstractElement;
10
use SimpleSAML\XML\Exception\InvalidDOMElementException;
11
use SimpleSAML\XML\ExtendableAttributesTrait;
12
use SimpleSAML\XML\ExtendableElementTrait;
13
use SimpleSAML\XML\XsNamespace as NS;
14
15
/**
16
 * Class representing a 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
    /** @var string */
26
    public const LOCALNAME = 'detail';
27
28
    /** @var null */
29
    public const NS = null;
30
31
    /** @var null */
32
    public const NS_PREFIX = null;
33
34
    /** The namespace-attribute for the xs:any element */
35
    public const XS_ANY_ELT_NAMESPACE = NS::ANY;
36
37
    /** The namespace-attribute for the xs:anyAttribute element */
38
    public const XS_ANY_ATTR_NAMESPACE = NS::ANY;
39
40
41
    /**
42
     * Initialize a soap:Detail
43
     *
44
     * @param list<\SimpleSAML\XML\SerializableElementInterface> $children
45
     * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP\XML\env_200106\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
46
     */
47
    public function __construct(array $children = [], array $namespacedAttributes = [])
48
    {
49
        $this->setElements($children);
50
        $this->setAttributesNS($namespacedAttributes);
51
    }
52
53
54
    /**
55
     * Test if an object, at the state it's in, would produce an empty XML-element
56
     *
57
     * @return bool
58
     */
59
    public function isEmptyElement(): bool
60
    {
61
        return empty($this->elements) && empty($this->namespacedAttributes);
62
    }
63
64
65
    /*
66
     * Convert XML into an Detail element
67
     *
68
     * @param \DOMElement $xml The XML element we should load
69
     * @return static
70
     *
71
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
72
     *   If the qualified name of the supplied element is wrong
73
     */
74
    public static function fromXML(DOMElement $xml): static
75
    {
76
        Assert::same($xml->localName, 'detail', InvalidDOMElementException::class);
77
        Assert::same($xml->namespaceURI, Detail::NS, InvalidDOMElementException::class);
78
79
        return new static(
80
            self::getChildElementsFromXML($xml),
81
            self::getAttributesNSFromXML($xml),
82
        );
83
    }
84
85
86
    /**
87
     * Convert this Detail to XML.
88
     *
89
     * @param \DOMElement|null $parent The element we should add this Detail to.
90
     * @return \DOMElement This Detail-element.
91
     */
92
    public function toXML(?DOMElement $parent = null): DOMElement
93
    {
94
        $e = $this->instantiateParentElement($parent);
95
96
        foreach ($this->getAttributesNS() as $attr) {
97
            $attr->toXML($e);
98
        }
99
100
        /** @psalm-var \SimpleSAML\XML\SerializableElementInterface $child */
101
        foreach ($this->getElements() as $child) {
102
            $child->toXML($e);
103
        }
104
105
        return $e;
106
    }
107
}
108