AbstractSignOutBasisType   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 20
dl 0
loc 72
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A toXML() 0 15 4
A fromXML() 0 8 1
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\ExtendableAttributesTrait;
10
use SimpleSAML\XML\ExtendableElementTrait;
11
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12
use SimpleSAML\XMLSchema\Exception\MissingElementException;
13
use SimpleSAML\XMLSchema\XML\Constants\NS;
14
15
/**
16
 * A SignOutBasisType
17
 *
18
 * @package simplesamlphp/ws-security
19
 */
20
abstract class AbstractSignOutBasisType extends AbstractFedElement
21
{
22
    use ExtendableAttributesTrait;
23
    use ExtendableElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\ExtendableElementTrait requires some properties which are not provided by SimpleSAML\WSSecurity\XM...bstractSignOutBasisType: $namespaceURI, $localName, $childNodes
Loading history...
24
25
26
    /** The namespace-attribute for the xs:anyAttribute element */
27
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
28
29
    /** The namespace-attribute for the xs:any element */
30
    public const XS_ANY_ELT_NAMESPACE = NS::OTHER;
31
32
33
    /**
34
     * SignOutBasisType constructor.
35
     *
36
     * @param array<\SimpleSAML\XML\SerializableElementInterface> $children
37
     * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
38
     */
39
    final public function __construct(
40
        array $children = [],
41
        array $namespacedAttributes = [],
42
    ) {
43
        Assert::minCount($children, 1, MissingElementException::class);
44
45
        $this->setElements($children);
46
        $this->setAttributesNS($namespacedAttributes);
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
            self::getAttributesNSFromXML($xml),
67
        );
68
    }
69
70
71
    /**
72
     * Add this SignOutBasisType to an XML element.
73
     *
74
     * @param \DOMElement|null $parent The element we should append this username token to.
75
     * @return \DOMElement
76
     */
77
    public function toXML(?DOMElement $parent = null): DOMElement
78
    {
79
        $e = parent::instantiateParentElement($parent);
80
81
        foreach ($this->getAttributesNS() as $attr) {
82
            $attr->toXML($e);
83
        }
84
85
        foreach ($this->getElements() as $child) {
86
            if (!$child->isEmptyElement()) {
87
                $child->toXML($e);
88
            }
89
        }
90
91
        return $e;
92
    }
93
}
94