ReferenceParameters   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 21
dl 0
loc 80
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fromXML() 0 8 1
A isEmptyElement() 0 3 2
A toXML() 0 16 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\wsa_200508;
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\ExtendableElementTrait;
12
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
13
use SimpleSAML\XML\XsNamespace as NS;
14
15
/**
16
 * Class representing a wsa:ReferenceParameters element.
17
 *
18
 * @package simplesamlphp/ws-security
19
 */
20
final class ReferenceParameters extends AbstractWsaElement implements SchemaValidatableElementInterface
21
{
22
    use ExtendableAttributesTrait;
23
    use ExtendableElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\ExtendableElementTrait requires some properties which are not provided by SimpleSAML\WSSecurity\XM...508\ReferenceParameters: $namespaceURI, $localName, $childNodes
Loading history...
24
    use SchemaValidatableElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\SchemaValidatableElementTrait requires some properties which are not provided by SimpleSAML\WSSecurity\XM...508\ReferenceParameters: $message, $line
Loading history...
25
26
    /** The namespace-attribute for the xs:any element */
27
    public const XS_ANY_ELT_NAMESPACE = NS::ANY;
28
29
    /** The namespace-attribute for the xs:anyAttribute element */
30
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
31
32
33
    /**
34
     * Initialize a wsa:ReferenceParameters
35
     *
36
     * @param \SimpleSAML\XML\SerializableElementInterface[] $children
37
     * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
0 ignored issues
show
Bug introduced by
The type SimpleSAML\WSSecurity\XML\wsa_200508\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...
38
     */
39
    public function __construct(array $children = [], array $namespacedAttributes = [])
40
    {
41
        $this->setElements($children);
42
        $this->setAttributesNS($namespacedAttributes);
43
    }
44
45
46
    /**
47
     * Test if an object, at the state it's in, would produce an empty XML-element
48
     *
49
     * @return bool
50
     */
51
    public function isEmptyElement(): bool
52
    {
53
        return empty($this->elements) && empty($this->namespacedAttributes);
54
    }
55
56
57
    /*
58
     * Convert XML into an ReferenceParameters element
59
     *
60
     * @param \DOMElement $xml The XML element we should load
61
     * @return static
62
     *
63
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
64
     *   If the qualified name of the supplied element is wrong
65
     */
66
    public static function fromXML(DOMElement $xml): static
67
    {
68
        Assert::same($xml->localName, 'ReferenceParameters', InvalidDOMElementException::class);
69
        Assert::same($xml->namespaceURI, ReferenceParameters::NS, InvalidDOMElementException::class);
70
71
        return new static(
72
            self::getChildElementsFromXML($xml),
73
            self::getAttributesNSFromXML($xml),
74
        );
75
    }
76
77
78
    /**
79
     * Convert this ReferenceParameters to XML.
80
     *
81
     * @param \DOMElement|null $parent The element we should add this ReferenceParameters to.
82
     * @return \DOMElement This Header-element.
83
     */
84
    public function toXML(?DOMElement $parent = null): DOMElement
85
    {
86
        $e = $this->instantiateParentElement($parent);
87
88
        foreach ($this->getAttributesNS() as $attr) {
89
            $attr->toXML($e);
90
        }
91
92
        /** @psalm-var \SimpleSAML\XML\SerializableElementInterface $child */
93
        foreach ($this->getElements() as $child) {
94
            if (!$child->isEmptyElement()) {
95
                $child->toXML($e);
96
            }
97
        }
98
99
        return $e;
100
    }
101
}
102