AbstractRequestedSecurityTokenType   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 14
dl 0
loc 59
c 0
b 0
f 0
rs 10

3 Methods

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