Issues (16)

src/SOAP12/XML/NotUnderstood.php (1 issue)

Labels
Severity
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, SchemaValidatableElementTrait};
11
use SimpleSAML\XMLSchema\Exception\{InvalidDOMElementException, MissingAttributeException};
12
use SimpleSAML\XMLSchema\Type\QNameValue;
13
14
/**
15
 * Class representing a env:NotUnderstood element.
16
 *
17
 * @package simplesaml/xml-soap
18
 */
19
final class NotUnderstood extends AbstractSoapElement implements SchemaValidatableElementInterface
20
{
21
    use SchemaValidatableElementTrait;
22
23
    /**
24
     * Initialize a soap:NotUnderstood
25
     *
26
     * @param \SimpleSAML\XMLSchema\Type\QNameValue $qname
27
     */
28
    public function __construct(
29
        protected QNameValue $qname,
30
    ) {
31
    }
32
33
34
    /**
35
     * @return \SimpleSAML\XMLSchema\Type\QNameValue
36
     */
37
    public function getQName(): QNameValue
38
    {
39
        return $this->qname;
40
    }
41
42
43
    /*
44
     * Convert XML into a NotUnderstood element
45
     *
46
     * @param \DOMElement $xml The XML element we should load
47
     * @return static
48
     *
49
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
50
     *   If the qualified name of the supplied element is wrong
51
     */
52
    public static function fromXML(DOMElement $xml): static
53
    {
54
        Assert::same($xml->localName, 'NotUnderstood', InvalidDOMElementException::class);
55
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
56
        Assert::notNull($xml->hasAttribute('qname'), MissingAttributeException::class);
57
58
        return new static(
59
            QNameValue::fromDocument($xml->getAttribute('qname'), $xml),
60
        );
61
    }
62
63
64
    /**
65
     * Convert this NotUnderstood to XML.
66
     *
67
     * @param \DOMElement|null $parent The element we should add this Body to.
68
     * @return \DOMElement This NotUnderstood-element.
69
     */
70
    public function toXML(?DOMElement $parent = null): DOMElement
71
    {
72
        $e = $this->instantiateParentElement($parent);
73
74
        if (!$e->lookupPrefix($this->getQName()->getNamespaceURI()->getValue())) {
75
            $namespace = new XMLAttribute(
76
                'http://www.w3.org/2000/xmlns/',
77
                'xmlns',
78
                $this->getQName()->getNamespacePrefix()->getValue(),
79
                $this->getQName()->getNamespaceURI(),
0 ignored issues
show
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

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