Upgrade   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

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

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