UsingAddressing   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 12
dl 0
loc 54
c 1
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toXML() 0 9 2
A fromXML() 0 6 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\wsaw;
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\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
12
use SimpleSAML\XML\XsNamespace as NS;
13
14
/**
15
 * Class defining the UsingAddressing element
16
 *
17
 * @package simplesamlphp/ws-security
18
 */
19
final class UsingAddressing extends AbstractWsawElement implements SchemaValidatableElementInterface
20
{
21
    use ExtendableAttributesTrait;
22
    use SchemaValidatableElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\SchemaValidatableElementTrait requires some properties which are not provided by SimpleSAML\WSSecurity\XML\wsaw\UsingAddressing: $message, $line
Loading history...
23
24
    /** The namespace-attribute for the xs:anyAttribute element */
25
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
26
27
28
    /**
29
     * UsingAddressing constructor
30
     *
31
     * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
32
     */
33
    final public function __construct(
34
        array $namespacedAttributes = [],
35
    ) {
36
        $this->setAttributesNS($namespacedAttributes);
37
    }
38
39
40
    /**
41
     * Create an instance of this object from its XML representation.
42
     *
43
     * @param \DOMElement $xml
44
     * @return static
45
     *
46
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
47
     *   if the qualified name of the supplied element is wrong
48
     */
49
    public static function fromXML(DOMElement $xml): static
50
    {
51
        Assert::same($xml->localName, static::getLocalName(), 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

51
        Assert::/** @scrutinizer ignore-call */ 
52
                same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
Loading history...
52
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
53
54
        return new static(self::getAttributesNSFromXML($xml));
55
    }
56
57
58
    /**
59
     * Convert this UsingAddressing to XML.
60
     *
61
     * @param \DOMElement|null $parent The element we should append this class to.
62
     * @return \DOMElement The XML element after adding the data corresponding to this UsingAddressing.
63
     */
64
    public function toXML(?DOMElement $parent = null): DOMElement
65
    {
66
        $e = $this->instantiateParentElement($parent);
67
68
        foreach ($this->getAttributesNS() as $attr) {
69
            $attr->toXML($e);
70
        }
71
72
        return $e;
73
    }
74
}
75