Completed
Push — master ( da4b66...3ae217 )
by Tim
19s queued 15s
created

AbstractStatusDetailType   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 17
c 1
b 0
f 0
dl 0
loc 72
rs 10

4 Methods

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