AbstractQNameAssertionType::fromXML()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 12
c 1
b 0
f 0
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\sp_200702;
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\XsNamespace as NS;
12
13
use function sprintf;
14
15
/**
16
 * Class representing WS security policy QNameAssertionType.
17
 *
18
 * @package simplesamlphp/ws-security
19
 */
20
abstract class AbstractQNameAssertionType extends AbstractSpElement
21
{
22
    use ExtendableAttributesTrait;
23
24
    /** The namespace-attribute for the xs:anyAttribute element */
25
    public const XS_ANY_ATTR_NAMESPACE = NS::ANY;
26
27
28
    /**
29
     * AbstractQNameAssertionType constructor.
30
     *
31
     * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
0 ignored issues
show
Bug introduced by
The type SimpleSAML\WSSecurity\XML\sp_200702\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...
32
     */
33
    final public function __construct(
34
        array $namespacedAttributes = [],
35
    ) {
36
        $this->setAttributesNS($namespacedAttributes);
37
    }
38
39
40
    /**
41
     * Initialize an QNameAssertionType.
42
     *
43
     * Note: this method cannot be used when extending this class, if the constructor has a different signature.
44
     *
45
     * @param \DOMElement $xml The XML element we should load.
46
     * @return static
47
     *
48
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
49
     *   if the qualified name of the supplied element is wrong
50
     */
51
    public static function fromXML(DOMElement $xml): static
52
    {
53
        $qualifiedName = static::getClassName(static::class);
54
        Assert::eq(
55
            $xml->localName,
56
            $qualifiedName,
57
            sprintf('Unexpected name for QNameAssertion: %s. Expected: %s.', $xml->localName, $qualifiedName),
58
            InvalidDOMElementException::class,
59
        );
60
61
62
        return new static(self::getAttributesNSFromXML($xml));
63
    }
64
65
66
    /**
67
     * Convert this element to XML.
68
     *
69
     * @param \DOMElement|null $parent The element we should append this element to.
70
     * @return \DOMElement
71
     */
72
    public function toXML(?DOMElement $parent = null): DOMElement
73
    {
74
        $e = $this->instantiateParentElement($parent);
75
76
        foreach ($this->getAttributesNS() as $attr) {
77
            $attr->toXML($e);
78
        }
79
80
        return $e;
81
    }
82
}
83