NotUnderstood::getQName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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\Attribute as XMLAttribute;
10
use SimpleSAML\XML\SchemaValidatableElementInterface;
11
use SimpleSAML\XML\SchemaValidatableElementTrait;
12
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
13
use SimpleSAML\XMLSchema\Exception\MissingAttributeException;
14
use SimpleSAML\XMLSchema\Type\QNameValue;
15
16
/**
17
 * Class representing a env:NotUnderstood element.
18
 *
19
 * @package simplesaml/xml-soap
20
 */
21
final class NotUnderstood extends AbstractSoapElement implements SchemaValidatableElementInterface
22
{
23
    use SchemaValidatableElementTrait;
24
25
26
    /**
27
     * Initialize a soap:NotUnderstood
28
     *
29
     * @param \SimpleSAML\XMLSchema\Type\QNameValue $qname
30
     */
31
    public function __construct(
32
        protected QNameValue $qname,
33
    ) {
34
    }
35
36
37
    /**
38
     * @return \SimpleSAML\XMLSchema\Type\QNameValue
39
     */
40
    public function getQName(): QNameValue
41
    {
42
        return $this->qname;
43
    }
44
45
46
    /*
47
     * Convert XML into a NotUnderstood element
48
     *
49
     * @param \DOMElement $xml The XML element we should load
50
     * @return static
51
     *
52
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
53
     *   If the qualified name of the supplied element is wrong
54
     */
55
    public static function fromXML(DOMElement $xml): static
56
    {
57
        Assert::same($xml->localName, 'NotUnderstood', InvalidDOMElementException::class);
58
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
59
        Assert::notNull($xml->hasAttribute('qname'), MissingAttributeException::class);
60
61
        return new static(
62
            QNameValue::fromDocument($xml->getAttribute('qname'), $xml),
63
        );
64
    }
65
66
67
    /**
68
     * Convert this NotUnderstood to XML.
69
     *
70
     * @param \DOMElement|null $parent The element we should add this Body to.
71
     * @return \DOMElement This NotUnderstood-element.
72
     */
73
    public function toXML(?DOMElement $parent = null): DOMElement
74
    {
75
        $e = $this->instantiateParentElement($parent);
76
77
        if (!$e->lookupPrefix($this->getQName()->getNamespaceURI()->getValue())) {
78
            $namespace = new XMLAttribute(
79
                'http://www.w3.org/2000/xmlns/',
80
                'xmlns',
81
                $this->getQName()->getNamespacePrefix()->getValue(),
82
                $this->getQName()->getNamespaceURI(),
0 ignored issues
show
Bug introduced by
It seems like $this->getQName()->getNamespaceURI() can also be of type null; however, parameter $attrValue of SimpleSAML\XML\Attribute::__construct() does only seem to accept SimpleSAML\XMLSchema\Typ...face\ValueTypeInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

82
                /** @scrutinizer ignore-type */ $this->getQName()->getNamespaceURI(),
Loading history...
83
            );
84
            $namespace->toXML($e);
85
        }
86
87
        $e->setAttribute('qname', strval($this->getQName()->getValue()));
88
89
        return $e;
90
    }
91
}
92