Passed
Branch feature/php8.3 (4d3b0a)
by Tim
17:15
created

AbstractAnyType   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

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