AbstractQNameAssertionType   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 14
dl 0
loc 62
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 12 1
A toXML() 0 9 2
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\sp_200507;
6
7
use DOMElement;
8
use SimpleSAML\WSSecurity\Assert\Assert;
9
use SimpleSAML\XML\ExtendableAttributesTrait;
10
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
11
use SimpleSAML\XMLSchema\XML\Constants\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
25
    /** The namespace-attribute for the xs:anyAttribute element */
26
    public const XS_ANY_ATTR_NAMESPACE = NS::ANY;
27
28
29
    /**
30
     * AbstractQNameAssertionType constructor.
31
     *
32
     * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
0 ignored issues
show
Bug introduced by
The type SimpleSAML\WSSecurity\XML\sp_200507\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...
33
     */
34
    final public function __construct(
35
        array $namespacedAttributes = [],
36
    ) {
37
        $this->setAttributesNS($namespacedAttributes);
38
    }
39
40
41
    /**
42
     * Initialize an QNameAssertionType.
43
     *
44
     * Note: this method cannot be used when extending this class, if the constructor has a different signature.
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
        $qualifiedName = static::getClassName(static::class);
55
        Assert::eq(
56
            $xml->localName,
57
            $qualifiedName,
58
            sprintf('Unexpected name for QNameAssertion: %s. Expected: %s.', $xml->localName, $qualifiedName),
59
            InvalidDOMElementException::class,
60
        );
61
62
63
        return new static(self::getAttributesNSFromXML($xml));
64
    }
65
66
67
    /**
68
     * Convert this element to XML.
69
     *
70
     * @param \DOMElement|null $parent The element we should append this element to.
71
     * @return \DOMElement
72
     */
73
    public function toXML(?DOMElement $parent = null): DOMElement
74
    {
75
        $e = $this->instantiateParentElement($parent);
76
77
        foreach ($this->getAttributesNS() as $attr) {
78
            $attr->toXML($e);
79
        }
80
81
        return $e;
82
    }
83
}
84