isEmptyElement()   A
last analyzed

Complexity

Conditions 1
Paths 1

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 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\fed;
6
7
use DOMElement;
8
use SimpleSAML\WSSecurity\Assert\Assert;
9
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10
use SimpleSAML\XML\ExtendableAttributesTrait;
11
use SimpleSAML\XML\XsNamespace as NS;
12
13
/**
14
 * Class defining the FederationMetadataHandlerType element
15
 *
16
 * @package simplesamlphp/ws-security
17
 */
18
abstract class AbstractFederationMetadataHandlerType extends AbstractFedElement
19
{
20
    use ExtendableAttributesTrait;
21
22
    /** The namespace-attribute for the xs:anyAttribute element */
23
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
24
25
26
    /**
27
     * AbstractFederationMetadataHandlerType constructor
28
     *
29
     * @param \SimpleSAML\XML\Attribute[] $namespacedAttributes
30
     */
31
    final public function __construct(
32
        array $namespacedAttributes = [],
33
    ) {
34
        $this->setAttributesNS($namespacedAttributes);
35
    }
36
37
38
    /**
39
     * Test if an object, at the state it's in, would produce an empty XML-element
40
     *
41
     * @return bool
42
     */
43
    public function isEmptyElement(): bool
44
    {
45
        return empty($this->getAttributesNS());
46
    }
47
48
49
    /**
50
     * Create an instance of this object from its XML representation.
51
     *
52
     * @param \DOMElement $xml
53
     * @return static
54
     *
55
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
56
     *   if the qualified name of the supplied element is wrong
57
     */
58
    public static function fromXML(DOMElement $xml): static
59
    {
60
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
61
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
62
63
        return new static(
64
            self::getAttributesNSFromXML($xml),
65
        );
66
    }
67
68
69
    /**
70
     * Add this FederationMetadataHandlerType to an XML element.
71
     *
72
     * @param \DOMElement|null $parent The element we should append this FederationMetadataHandlerType to.
73
     * @return \DOMElement
74
     */
75
    public function toXML(?DOMElement $parent = null): DOMElement
76
    {
77
        $e = parent::instantiateParentElement($parent);
78
79
        foreach ($this->getAttributesNS() as $attr) {
80
            $attr->toXML($e);
81
        }
82
83
        return $e;
84
    }
85
}
86