Completed
Push — master ( f72cfb...4ef12f )
by Tim
21s queued 18s
created

AbstractAnyType::isEmptyElement()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSchema\XML\xs;
6
7
use DOMElement;
8
use SimpleSAML\XML\{ExtendableAttributesTrait, ExtendableElementTrait};
9
use SimpleSAML\XMLSchema\XML\xs\NamespaceEnum;
10
11
/**
12
 * Abstract class to be implemented by all the classes that use the xs:anyType complex type
13
 *
14
 * @package simplesamlphp/xml-common
15
 */
16
abstract class AbstractAnyType extends AbstractXsElement
17
{
18
    use ExtendableAttributesTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\ExtendableAttributesTrait requires some properties which are not provided by SimpleSAML\XMLSchema\XML\xs\AbstractAnyType: $localName, $nodeValue, $namespaceURI, $prefix, $attributes
Loading history...
19
    use ExtendableElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\ExtendableElementTrait requires some properties which are not provided by SimpleSAML\XMLSchema\XML\xs\AbstractAnyType: $namespaceURI, $localName, $childNodes
Loading history...
20
21
    /** The namespace-attribute for the xs:any element */
22
    public const XS_ANY_ELT_NAMESPACE = NamespaceEnum::Any;
23
24
    /** The namespace-attribute for the xs:anyAttribute element */
25
    public const XS_ANY_ATTR_NAMESPACE = NamespaceEnum::Any;
26
27
28
    /**
29
     * AbstractAnyType constructor
30
     *
31
     * @param array<\SimpleSAML\XML\SerializableElementInterface> $elements
32
     * @param array<\SimpleSAML\XML\Attribute> $attributes
33
     */
34
    public function __construct(
35
        array $elements = [],
36
        array $attributes = [],
37
    ) {
38
        $this->setElements($elements);
39
        $this->setAttributesNS($attributes);
40
    }
41
42
43
    /**
44
     * Test if an object, at the state it's in, would produce an empty XML-element
45
     *
46
     * @return bool
47
     */
48
    public function isEmptyElement(): bool
49
    {
50
        return empty($this->getAttributesNS())
51
            && empty($this->getElements());
52
    }
53
54
55
    /**
56
     * Add this AnyType to an XML element.
57
     *
58
     * @param \DOMElement|null $parent The element we should append this anyType to.
59
     * @return \DOMElement
60
     */
61
    public function toXML(?DOMElement $parent = null): DOMElement
62
    {
63
        $e = parent::instantiateParentElement($parent);
64
65
        foreach ($this->getAttributesNS() as $attr) {
66
            $attr->toXML($e);
67
        }
68
69
        foreach ($this->getElements() as $elt) {
70
            $elt->toXML($e);
71
        }
72
73
        return $e;
74
    }
75
}
76