Passed
Pull Request — master (#6)
by Tim
02:14
created

AbstractExtensibleDocumented::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\wsdl;
6
7
use DOMElement;
8
use SimpleSAML\XML\ExtendableElementTrait;
9
use SimpleSAML\XML\XsNamespace as NS;
10
11
/**
12
 * Abstract class representing the tExtensibleDocumented type.
13
 *
14
 * @package simplesamlphp/ws-security
15
 */
16
abstract class AbstractExtensibleDocumented extends AbstractDocumented
17
{
18
    use ExtendableElementTrait;
19
20
    /** The namespace-attribute for the xs:any element */
21
    public const XS_ANY_ELT_NAMESPACE = NS::OTHER;
22
23
    /**
24
     * Initialize a wsdl:tDocumented
25
     *
26
     * @param \SimpleSAML\XML\Chunk[] $elements
27
     */
28
    public function __construct(array $elements)
29
    {
30
        parent::__construct(/* TODO wsdl:documentation not implemented */);
31
        $this->setElements($elements);
32
    }
33
34
35
    /**
36
     * Test if an object, at the state it's in, would produce an empty XML-element
37
     *
38
     * @return bool
39
     */
40
    public function isEmptyElement(): bool
41
    {
42
        return parent::isEmptyElement() && empty($this->elements);
43
    }
44
45
46
    /**
47
     * Convert this tExtensibleDocumented to XML.
48
     *
49
     * @param \DOMElement|null $parent The element we are converting to XML.
50
     * @return \DOMElement The XML element after adding the data corresponding to this tExtensibleDocumented.
51
     */
52
    public function toXML(DOMElement $parent = null): DOMElement
53
    {
54
        $e = parent::toXML($parent);
55
56
        foreach ($this->getElements() as $elt) {
57
            $elt->toXML($e);
58
        }
59
60
        return $e;
61
    }
62
}
63