ReferenceProperties   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 14
dl 0
loc 68
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 7 1
A isEmptyElement() 0 3 1
A __construct() 0 3 1
A toXML() 0 12 3
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\ExtendableElementTrait;
11
use SimpleSAML\XML\XsNamespace as NS;
12
13
/**
14
 * Class representing a wsa:ReferenceProperties element.
15
 *
16
 * @package simplesamlphp/ws-security
17
 */
18
final class ReferenceProperties extends AbstractWsaElement
19
{
20
    use ExtendableElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\ExtendableElementTrait requires some properties which are not provided by SimpleSAML\WSSecurity\XM...408\ReferenceProperties: $namespaceURI, $localName, $childNodes
Loading history...
21
22
    /** The namespace-attribute for the xs:any element */
23
    public const XS_ANY_ELT_NAMESPACE = NS::ANY;
24
25
26
    /**
27
     * Initialize a wsa:ReferenceProperties
28
     *
29
     * @param \SimpleSAML\XML\SerializableElementInterface[] $children
30
     */
31
    public function __construct(array $children = [])
32
    {
33
        $this->setElements($children);
34
    }
35
36
37
    /**
38
     * Test if an object, at the state it's in, would produce an empty XML-element
39
     *
40
     * @return bool
41
     */
42
    public function isEmptyElement(): bool
43
    {
44
        return empty($this->elements);
45
    }
46
47
48
    /*
49
     * Convert XML into an ReferenceProperties element
50
     *
51
     * @param \DOMElement $xml The XML element we should load
52
     * @return static
53
     *
54
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
55
     *   If the qualified name of the supplied element is wrong
56
     */
57
    public static function fromXML(DOMElement $xml): static
58
    {
59
        Assert::same($xml->localName, 'ReferenceProperties', InvalidDOMElementException::class);
0 ignored issues
show
Bug introduced by
The method same() does not exist on SimpleSAML\WSSecurity\Assert\Assert. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
        Assert::/** @scrutinizer ignore-call */ 
60
                same($xml->localName, 'ReferenceProperties', InvalidDOMElementException::class);
Loading history...
60
        Assert::same($xml->namespaceURI, ReferenceProperties::NS, InvalidDOMElementException::class);
61
62
        return new static(
63
            self::getChildElementsFromXML($xml),
64
        );
65
    }
66
67
68
    /**
69
     * Convert this ReferenceProperties to XML.
70
     *
71
     * @param \DOMElement|null $parent The element we should add this ReferenceProperties to.
72
     * @return \DOMElement This Header-element.
73
     */
74
    public function toXML(?DOMElement $parent = null): DOMElement
75
    {
76
        $e = $this->instantiateParentElement($parent);
77
78
        /** @psalm-var \SimpleSAML\XML\SerializableElementInterface $child */
79
        foreach ($this->getElements() as $child) {
80
            if (!$child->isEmptyElement()) {
81
                $child->toXML($e);
82
            }
83
        }
84
85
        return $e;
86
    }
87
}
88