Passed
Push — master ( afad0f...b4dd13 )
by Tim
01:55
created

Upgrade::setSupportedEnvelope()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace SimpleSAML\SOAP\XML\env;
4
5
use DOMElement;
6
use SimpleSAML\Assert\Assert;
7
use SimpleSAML\XML\Exception\InvalidDOMElementException;
8
use SimpleSAML\XML\Exception\SchemaViolationException;
9
10
/**
11
 * Class representing a env:Upgrade element.
12
 *
13
 * @package simplesaml/xml-soap
14
 */
15
final class Upgrade extends AbstractSoapElement
16
{
17
    /** @var \SimpleSAML\SOAP\XML\SupportedEnvelope[] */
18
    protected array $supportedEnvelope;
19
20
21
    /**
22
     * Initialize a env:Upgrade
23
     *
24
     * @param \SimpleSAML\SOAP\XML\SupportedEnvelope[] $supportedEnvelope
25
     */
26
    public function __construct(array $supportedEnvelope)
27
    {
28
        $this->setSupportedEnvelope($supportedEnvelope);
29
    }
30
31
32
    /**
33
     * @return \SimpleSAML\SOAP\XML\SupportedEnvelope[]
34
     */
35
    public function getSupportedEnvelope(): array
36
    {
37
        return $this->supportedEnvelope;
38
    }
39
40
41
    /**
42
     * @param \SimpleSAML\SOAP\XML\SupportedEnvelope $supportedEnvelope
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP\XML\SupportedEnvelope was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
43
     */
44
    private function setSupportedEnvelope(array $supportedEnvelope): void
45
    {
46
        Assert::allIsInstanceOf($supportedEnvelope, SupportedEnvelope::class, SchemaViolationException::class);
47
        Assert::minCount($supportedEnvelope, 1, SchemaViolationException::class);
48
        $this->supportedEnvelope = $supportedEnvelope;
49
    }
50
51
52
    /**
53
     * Convert this element to XML.
54
     *
55
     * @param \DOMElement|null $parent The element we should append this element to.
56
     * @return \DOMElement
57
     */
58
    public function toXML(DOMElement $parent = null): DOMElement
59
    {
60
        $e = $this->instantiateParentElement($parent);
61
62
        foreach ($this->supportedEnvelope as $supportedEnvelope) {
63
            $supportedEnvelope->toXML($e);
64
        }
65
66
        return $e;
67
    }
68
69
    /**
70
     * Convert XML into a Upgrade
71
     *
72
     * @param \DOMElement $xml The XML element we should load
73
     * @return static
74
     *
75
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
76
     *   If the qualified name of the supplied element is wrong
77
     */
78
    public static function fromXML(DOMElement $xml): static
79
    {
80
        Assert::same($xml->localName, 'Upgrade', InvalidDOMElementException::class);
81
        Assert::same($xml->namespaceURI, Upgrade::NS, InvalidDOMElementException::class);
82
83
        $supportedEnvelope = SupportedEnvelope::getChildrenOfClass($xml);
84
        Assert::minCount($supportedEnvelope, 1, SchemaViolationException::class);
85
86
        return new static($supportedEnvelope);
87
    }
88
}
89