Upgrade   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 15
dl 0
loc 64
rs 10
c 0
b 0
f 0

4 Methods

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