Detail::fromXML()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SOAP\XML\env_200305;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10
use SimpleSAML\XML\ExtendableAttributesTrait;
11
use SimpleSAML\XML\ExtendableElementTrait;
12
use SimpleSAML\XML\XsNamespace as 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
    /** The namespace-attribute for the xs:any element */
25
    public const XS_ANY_ELT_NAMESPACE = NS::ANY;
26
27
    /** The namespace-attribute for the xs:anyAttribute element */
28
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
29
30
31
    /**
32
     * Initialize a soap:Detail
33
     *
34
     * @param list<\SimpleSAML\XML\SerializableElementInterface> $children
35
     * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP\XML\env_200305\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...
36
     */
37
    public function __construct(array $children = [], array $namespacedAttributes = [])
38
    {
39
        $this->setElements($children);
40
        $this->setAttributesNS($namespacedAttributes);
41
    }
42
43
44
    /**
45
     * Test if an object, at the state it's in, would produce an empty XML-element
46
     *
47
     * @return bool
48
     */
49
    public function isEmptyElement(): bool
50
    {
51
        return empty($this->elements) && empty($this->namespacedAttributes);
52
    }
53
54
55
    /*
56
     * Convert XML into an Detail element
57
     *
58
     * @param \DOMElement $xml The XML element we should load
59
     * @return static
60
     *
61
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
62
     *   If the qualified name of the supplied element is wrong
63
     */
64
    public static function fromXML(DOMElement $xml): static
65
    {
66
        Assert::same($xml->localName, 'Detail', InvalidDOMElementException::class);
67
        Assert::same($xml->namespaceURI, Detail::NS, InvalidDOMElementException::class);
68
69
        return new static(
70
            self::getChildElementsFromXML($xml),
71
            self::getAttributesNSFromXML($xml),
72
        );
73
    }
74
75
76
    /**
77
     * Convert this Detail to XML.
78
     *
79
     * @param \DOMElement|null $parent The element we should add this Detail to.
80
     * @return \DOMElement This Detail-element.
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
        /** @psalm-var \SimpleSAML\XML\SerializableElementInterface $child */
91
        foreach ($this->getElements() as $child) {
92
            $child->toXML($e);
93
        }
94
95
        return $e;
96
    }
97
}
98