AbstractAttributedQNameType::fromXML()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\wsa_200408;
6
7
use DOMElement;
8
use SimpleSAML\WSSecurity\Assert\Assert;
9
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10
use SimpleSAML\XML\ExtendableAttributesTrait;
11
use SimpleSAML\XML\QNameElementTrait;
12
use SimpleSAML\XML\XsNamespace as NS;
13
14
/**
15
 * Class representing WS-addressing AttributedQNameType.
16
 *
17
 * You can extend the class without extending the constructor. Then you can use the methods available and the class
18
 * will generate an element with the same name as the extending class
19
 * (e.g. \SimpleSAML\WSSecurity\wsa\ProblemHeaderQName).
20
 *
21
 * @package simplesamlphp/ws-security
22
 */
23
abstract class AbstractAttributedQNameType extends AbstractWsaElement
24
{
25
    use ExtendableAttributesTrait;
26
    use QNameElementTrait;
27
28
    /** The namespace-attribute for the xs:anyElement element */
29
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
30
31
32
    /**
33
     * AbstractAttributedQNameType constructor.
34
     *
35
     * @param string $value The QName.
36
     * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
0 ignored issues
show
Bug introduced by
The type SimpleSAML\WSSecurity\XML\wsa_200408\list 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...
37
     */
38
    final public function __construct(string $value, array $namespacedAttributes = [])
39
    {
40
        $this->setContent($value);
41
        $this->setAttributesNS($namespacedAttributes);
42
    }
43
44
45
    /**
46
     * Convert XML into a class instance
47
     *
48
     * @param \DOMElement $xml The XML element we should load
49
     * @return static
50
     *
51
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
52
     *   If the qualified name of the supplied element is wrong
53
     */
54
    public static function fromXML(DOMElement $xml): static
55
    {
56
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
57
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
58
59
        return new static($xml->textContent, self::getAttributesNSFromXML($xml));
60
    }
61
62
63
    /**
64
     * Convert this element to XML.
65
     *
66
     * @param \DOMElement|null $parent The element we should append this element to.
67
     * @return \DOMElement
68
     */
69
    public function toXML(?DOMElement $parent = null): DOMElement
70
    {
71
        $e = $this->instantiateParentElement($parent);
72
        $e->textContent = $this->getContent();
73
74
        foreach ($this->getAttributesNS() as $attr) {
75
            $attr->toXML($e);
76
        }
77
78
        return $e;
79
    }
80
}
81