AbstractStatusDetailType::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML11\XML\samlp;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Chunk;
10
use SimpleSAML\XML\ExtendableElementTrait;
11
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12
use SimpleSAML\XMLSchema\XML\Constants\NS;
13
14
/**
15
 * SAML StatusDetail data type.
16
 *
17
 * @package simplesamlphp/saml11
18
 */
19
abstract class AbstractStatusDetailType extends AbstractSamlpElement
20
{
21
    use ExtendableElementTrait;
22
23
24
    /** The namespace-attribute for the xs:any element */
25
    public const XS_ANY_ELT_NAMESPACE = NS::ANY;
26
27
28
    /**
29
     * Initialize a samlp:StatusDetail
30
     *
31
     * @param \SimpleSAML\XML\Chunk[] $details
32
     */
33
    final public function __construct(array $details = [])
34
    {
35
        $this->setElements($details);
36
    }
37
38
39
    /**
40
     * Test if an object, at the state it's in, would produce an empty XML-element
41
     *
42
     * @return bool
43
     */
44
    public function isEmptyElement(): bool
45
    {
46
        return empty($this->elements);
47
    }
48
49
50
    /**
51
     * Convert XML into a StatusDetail
52
     *
53
     * @param \DOMElement $xml The XML element we should load
54
     * @return static
55
     *
56
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
57
     *   if the qualified name of the supplied element is wrong
58
     */
59
    public static function fromXML(DOMElement $xml): static
60
    {
61
        Assert::same($xml->localName, 'StatusDetail', InvalidDOMElementException::class);
62
        Assert::same($xml->namespaceURI, StatusDetail::NS, InvalidDOMElementException::class);
63
64
        $details = [];
65
        foreach ($xml->childNodes as $detail) {
66
            if (!($detail instanceof DOMElement)) {
67
                continue;
68
            }
69
70
            $details[] = new Chunk($detail);
71
        }
72
73
        return new static($details);
74
    }
75
76
77
    /**
78
     * Convert this StatusDetail to XML.
79
     *
80
     * @param \DOMElement|null $parent The element we are converting to XML.
81
     * @return \DOMElement The XML element after adding the data corresponding to this StatusDetail.
82
     */
83
    public function toXML(?DOMElement $parent = null): DOMElement
84
    {
85
        $e = $this->instantiateParentElement($parent);
86
87
        foreach ($this->getElements() as $detail) {
88
            $detail->toXML($e);
89
        }
90
91
        return $e;
92
    }
93
}
94