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

isEmptyElement()   A

Complexity

Conditions 2
Paths 2

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 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\wsdl;
6
7
use DOMElement;
8
use SimpleSAML\XML\ExtendableAttributesTrait;
9
use SimpleSAML\XML\XsNamespace as NS;
10
11
/**
12
 * Abstract class representing the tExtensibleAttributesDocumented type.
13
 *
14
 * @package simplesamlphp/ws-security
15
 */
16
abstract class AbstractExtensibleAttributesDocumented extends AbstractDocumented
17
{
18
    use ExtendableAttributesTrait;
1 ignored issue
show
introduced by
The trait SimpleSAML\XML\ExtendableAttributesTrait requires some properties which are not provided by SimpleSAML\WSSecurity\XM...bleAttributesDocumented: $localName, $nodeValue, $namespaceURI, $prefix, $attributes
Loading history...
19
20
    /** The namespace-attribute for the xs:anyAttribute element */
21
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
22
23
24
    /**
25
     * Initialize a wsdl:tExtensibleAttributesDocumented
26
     *
27
     * @param \SimpleSAML\XML\Attribute[] $attributes
28
     */
29
    public function __construct(array $attributes = [])
30
    {
31
        parent::__construct(/* TODO wsdl:documentation not implemented */);
32
        $this->setAttributesNS($attributes);
33
    }
34
35
36
    /**
37
     * Test if an object, at the state it's in, would produce an empty XML-element
38
     *
39
     * @return bool
40
     */
41
    public function isEmptyElement(): bool
42
    {
43
        return parent::isEmptyElement() && empty($this->getAttributesNS());
44
    }
45
46
47
    /**
48
     * Convert this tExtensibleAttributesDocumented to XML.
49
     *
50
     * @param \DOMElement|null $parent The element we are converting to XML.
51
     * @return \DOMElement The XML element after adding the data corresponding to this tExtensibleAttributesDocumented.
52
     */
53
    public function toXML(DOMElement $parent = null): DOMElement
54
    {
55
        $e = parent::toXML($parent);
56
57
        foreach ($this->getAttributesNS() as $attr) {
58
            $attr->toXML($e);
59
        }
60
61
        return $e;
62
    }
63
}
64