AbstractKeyExchangeTokenType   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 14
dl 0
loc 69
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toXML() 0 11 3
A isEmptyElement() 0 3 1
A fromXML() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\wst_200512;
6
7
use DOMElement;
8
use SimpleSAML\WSSecurity\Assert\Assert;
9
use SimpleSAML\XML\ExtendableElementTrait;
10
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
11
use SimpleSAML\XMLSchema\XML\Constants\NS;
12
13
/**
14
 * Class defining the KeyExchangeTokenType element
15
 *
16
 * @package simplesamlphp/ws-security
17
 */
18
abstract class AbstractKeyExchangeTokenType extends AbstractWstElement
19
{
20
    use ExtendableElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\ExtendableElementTrait requires some properties which are not provided by SimpleSAML\WSSecurity\XM...actKeyExchangeTokenType: $namespaceURI, $localName, $childNodes
Loading history...
21
22
23
    /** The namespace-attribute for the xs:any element */
24
    public const XS_ANY_ELT_NAMESPACE = NS::ANY;
25
26
27
    /**
28
     * AbstractKeyExchangeTokenType constructor
29
     *
30
     * @param array<\SimpleSAML\XML\SerializableElementInterface> $children
31
     */
32
    final public function __construct(
33
        array $children = [],
34
    ) {
35
        $this->setElements($children);
36
    }
37
38
39
    /**
40
     * Test if an object, at the state it's in, would produce an empty XML-element
41
     *
42
     * @return bool
43
     */
44
    public function isEmptyElement(): bool
45
    {
46
        return empty($this->getElements());
47
    }
48
49
50
    /**
51
     * Create an instance of this object from its XML representation.
52
     *
53
     * @param \DOMElement $xml
54
     * @return static
55
     *
56
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
57
     *   if the qualified name of the supplied element is wrong
58
     */
59
    public static function fromXML(DOMElement $xml): static
60
    {
61
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
62
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
63
64
        return new static(
65
            self::getChildElementsFromXML($xml),
66
        );
67
    }
68
69
70
    /**
71
     * Add this KeyExchangeTokenType to an XML element.
72
     *
73
     * @param \DOMElement|null $parent The element we should append this username token to.
74
     * @return \DOMElement
75
     */
76
    public function toXML(?DOMElement $parent = null): DOMElement
77
    {
78
        $e = parent::instantiateParentElement($parent);
79
80
        foreach ($this->getElements() as $child) {
81
            if (!$child->isEmptyElement()) {
82
                $child->toXML($e);
83
            }
84
        }
85
86
        return $e;
87
    }
88
}
89