Passed
Push — master ( c726f3...c686fd )
by Tim
10:07
created

Upgrade   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 72
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

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