Passed
Push — master ( 8413b2...00f101 )
by Tim
02:19
created

AbstractWildcard::isEmptyElement()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 3
nop 0
dl 0
loc 5
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\XMLSchema\Type\IDValue;
9
use SimpleSAML\XMLSchema\Type\Schema\{NamespaceListValue, ProcessContentsValue};
10
11
use function strval;
12
13
/**
14
 * Abstract class representing the wildcard-type.
15
 *
16
 * @package simplesamlphp/xml-common
17
 */
18
abstract class AbstractWildcard extends AbstractAnnotated
19
{
20
    /**
21
     * Wildcard constructor
22
     *
23
     * @param \SimpleSAML\XMLSchema\Type\Schema\NamespaceListValue|null $namespace
24
     * @param \SimpleSAML\XMLSchema\Type\Schema\ProcessContentsValue|null $processContents
25
     * @param \SimpleSAML\XMLSchema\XML\Annotation|null $annotation
26
     * @param \SimpleSAML\XMLSchema\Type\IDValue|null $id
27
     * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
28
     */
29
    public function __construct(
30
        protected ?NamespaceListValue $namespace = null,
31
        protected ?ProcessContentsValue $processContents = null,
32
        ?Annotation $annotation = null,
33
        ?IDValue $id = null,
34
        array $namespacedAttributes = [],
35
    ) {
36
        parent::__construct($annotation, $id, $namespacedAttributes);
37
    }
38
39
40
    /**
41
     * Collect the value of the namespace-property
42
     *
43
     * @return \SimpleSAML\XMLSchema\Type\Schema\NamespaceListValue|null
44
     */
45
    public function getNamespace(): ?NamespaceListValue
46
    {
47
        return $this->namespace;
48
    }
49
50
51
    /**
52
     * Collect the value of the processContents-property
53
     *
54
     * @return \SimpleSAML\XMLSchema\Type\Schema\ProcessContentsValue|null
55
     */
56
    public function getProcessContents(): ?ProcessContentsValue
57
    {
58
        return $this->processContents;
59
    }
60
61
62
    /**
63
     * Test if an object, at the state it's in, would produce an empty XML-element
64
     *
65
     * @return bool
66
     */
67
    public function isEmptyElement(): bool
68
    {
69
        return parent::isEmptyElement() &&
70
            empty($this->getNamespace()) &&
71
            empty($this->getProcessContents());
72
    }
73
74
75
    /**
76
     * Add this Wildcard to an XML element.
77
     *
78
     * @param \DOMElement|null $parent The element we should append this Wildcard to.
79
     * @return \DOMElement
80
     */
81
    public function toXML(?DOMElement $parent = null): DOMElement
82
    {
83
        $e = parent::toXML($parent);
84
85
        if ($this->getNamespace() !== null) {
86
            $e->setAttribute('namespace', strval($this->getNamespace()));
87
        }
88
89
        if ($this->getProcessContents() !== null) {
90
            $e->setAttribute('processContents', strval($this->getProcessContents()));
91
        }
92
93
        return $e;
94
    }
95
}
96