Upgrade::toXML()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SOAP\XML\env_200305;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Constants as C;
10
use SimpleSAML\XML\Exception\InvalidDOMElementException;
11
use SimpleSAML\XML\Exception\SchemaViolationException;
12
use SimpleSAML\XML\SchemaValidatableElementInterface;
13
use SimpleSAML\XML\SchemaValidatableElementTrait;
14
15
/**
16
 * Class representing a env:Upgrade element.
17
 *
18
 * @package simplesaml/xml-soap
19
 */
20
final class Upgrade extends AbstractSoapElement implements SchemaValidatableElementInterface
21
{
22
    use SchemaValidatableElementTrait;
23
24
    /**
25
     * Initialize a env:Upgrade
26
     *
27
     * @param \SimpleSAML\SOAP\XML\env_200305\SupportedEnvelope[] $supportedEnvelope
28
     */
29
    public function __construct(
30
        protected array $supportedEnvelope,
31
    ) {
32
        Assert::maxCount($supportedEnvelope, C::UNBOUNDED_LIMIT);
33
        Assert::minCount($supportedEnvelope, 1, SchemaViolationException::class);
34
        Assert::allIsInstanceOf($supportedEnvelope, SupportedEnvelope::class, SchemaViolationException::class);
35
    }
36
37
38
    /**
39
     * @return \SimpleSAML\SOAP\XML\env_200305\SupportedEnvelope[]
40
     */
41
    public function getSupportedEnvelope(): array
42
    {
43
        return $this->supportedEnvelope;
44
    }
45
46
47
    /**
48
     * Convert this element to XML.
49
     *
50
     * @param \DOMElement|null $parent The element we should append this element to.
51
     * @return \DOMElement
52
     */
53
    public function toXML(?DOMElement $parent = null): DOMElement
54
    {
55
        $e = $this->instantiateParentElement($parent);
56
57
        foreach ($this->getSupportedEnvelope() as $supportedEnvelope) {
58
            $supportedEnvelope->toXML($e);
59
        }
60
61
        return $e;
62
    }
63
64
    /**
65
     * Convert XML into a Upgrade
66
     *
67
     * @param \DOMElement $xml The XML element we should load
68
     * @return static
69
     *
70
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
71
     *   If the qualified name of the supplied element is wrong
72
     */
73
    public static function fromXML(DOMElement $xml): static
74
    {
75
        Assert::same($xml->localName, 'Upgrade', InvalidDOMElementException::class);
76
        Assert::same($xml->namespaceURI, Upgrade::NS, InvalidDOMElementException::class);
77
78
        $supportedEnvelope = SupportedEnvelope::getChildrenOfClass($xml);
79
        Assert::minCount($supportedEnvelope, 1, SchemaViolationException::class);
80
81
        return new static($supportedEnvelope);
82
    }
83
}
84