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

SupportedEnvelope::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
11
/**
12
 * Class representing a env:SupportedEnvelope element.
13
 *
14
 * @package simplesaml/xml-soap
15
 */
16
final class SupportedEnvelope extends AbstractSoapElement
17
{
18
    /**
19
     * The qname attribute
20
     *
21
     * @var string
22
     */
23
    protected string $qname;
24
25
    /**
26
     * Initialize a soap:SupportedEnvelope
27
     *
28
     * @param string $qname
29
     */
30
    public function __construct(string $qname)
31
    {
32
        $this->setQName($qname);
33
    }
34
35
36
    /**
37
     * @return string
38
     */
39
    public function getQName(): string
40
    {
41
        return $this->qname;
42
    }
43
44
45
    /**
46
     * @param string $qname
47
     */
48
    private function setQName(string $qname): void
49
    {
50
        $this->qname = $qname;
51
    }
52
53
54
    /**
55
     * Convert XML into an SupportedEnvelope element
56
     *
57
     * @param \DOMElement $xml The XML element we should load
58
     * @return static
59
     *
60
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
61
     *   If the qualified name of the supplied element is wrong
62
     */
63
    public static function fromXML(DOMElement $xml): static
64
    {
65
        Assert::same($xml->localName, 'SupportedEnvelope', InvalidDOMElementException::class);
66
        Assert::same($xml->namespaceURI, SupportedEnvelope::NS, InvalidDOMElementException::class);
67
68
        /** @psalm-var string $qname */
69
        $qname = self::getAttribute($xml, 'qname');
70
71
        return new static($qname);
72
    }
73
74
75
    /**
76
     * Convert this SupportedEnvelope to XML.
77
     *
78
     * @param \DOMElement|null $parent The element we should add this SupportedEnvelope to.
79
     * @return \DOMElement This SupportedEnvelope-element.
80
     */
81
    public function toXML(DOMElement $parent = null): DOMElement
82
    {
83
        $e = $this->instantiateParentElement($parent);
84
        $e->setAttribute('qname', $this->getQName());
85
86
        return $e;
87
    }
88
}
89