SupportedEnvelope::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\XMLSchema\Exception\InvalidDOMElementException;
11
use SimpleSAML\XMLSchema\Exception\MissingAttributeException;
12
use SimpleSAML\XMLSchema\Type\QNameValue;
13
14
use function strval;
15
16
/**
17
 * Class representing a env:SupportedEnvelope element.
18
 *
19
 * @package simplesaml/xml-soap
20
 */
21
final class SupportedEnvelope extends AbstractSoapElement
0 ignored issues
show
Bug introduced by
The type SimpleSAML\SOAP12\XML\AbstractSoapElement 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...
22
{
23
    /**
24
     * Initialize a soap:SupportedEnvelope
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 SupportedEnvelope element
45
     *
46
     * @param \DOMElement $xml The XML element we should load
47
     *
48
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
49
     *   If the qualified name of the supplied element is wrong
50
     */
51
    public static function fromXML(DOMElement $xml): static
52
    {
53
        Assert::same($xml->localName, 'SupportedEnvelope', InvalidDOMElementException::class);
54
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
55
        Assert::notNull($xml->hasAttribute('qname'), MissingAttributeException::class);
56
57
        return new static(
58
            QNameValue::fromDocument($xml->getAttribute('qname'), $xml),
59
        );
60
    }
61
62
63
    /**
64
     * Convert this SupportedEnvelope to XML.
65
     *
66
     * @param \DOMElement|null $parent The element we should add this Body to.
67
     */
68
    public function toXML(?DOMElement $parent = null): DOMElement
69
    {
70
        $e = $this->instantiateParentElement($parent);
71
72
        if (!$e->lookupPrefix($this->getQName()->getNamespaceURI()->getValue())) {
73
            $namespace = new XMLAttribute(
74
                'http://www.w3.org/2000/xmlns/',
75
                'xmlns',
76
                $this->getQName()->getNamespacePrefix()->getValue(),
77
                $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

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