AbstractBinaryExchangeType   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 23
c 0
b 0
f 0
dl 0
loc 94
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A toXML() 0 13 2
A fromXML() 0 10 1
A getValueType() 0 3 1
A __construct() 0 8 1
A getEncodingType() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\wst_200512;
6
7
use DOMElement;
8
use SimpleSAML\WSSecurity\Assert\Assert;
9
use SimpleSAML\XML\ExtendableAttributesTrait;
10
use SimpleSAML\XML\TypedTextContentTrait;
11
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12
use SimpleSAML\XMLSchema\Type\AnyURIValue;
13
use SimpleSAML\XMLSchema\Type\StringValue;
14
use SimpleSAML\XMLSchema\XML\Constants\NS;
15
16
/**
17
 * A BinaryExchangeType element
18
 *
19
 * @package simplesamlphp/ws-security
20
 */
21
abstract class AbstractBinaryExchangeType extends AbstractWstElement
22
{
23
    use ExtendableAttributesTrait;
24
    use TypedTextContentTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\TypedTextContentTrait requires some properties which are not provided by SimpleSAML\WSSecurity\XM...tractBinaryExchangeType: $localName, $namespaceURI
Loading history...
25
26
27
    /** @var string */
28
    public const TEXTCONTENT_TYPE = StringValue::class;
29
30
    /** The namespace-attribute for the xs:anyAttribute element */
31
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
32
33
34
    /**
35
     * @param \SimpleSAML\XMLSchema\Type\StringValue $content
36
     * @param \SimpleSAML\XMLSchema\Type\AnyURIValue $valueType
37
     * @param \SimpleSAML\XMLSchema\Type\AnyURIValue $encodingType
38
     * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
39
     */
40
    final public function __construct(
41
        StringValue $content,
42
        protected AnyURIValue $valueType,
43
        protected AnyURIValue $encodingType,
44
        array $namespacedAttributes,
45
    ) {
46
        $this->setContent($content);
47
        $this->setAttributesNS($namespacedAttributes);
48
    }
49
50
51
    /**
52
     * Get the valueType property.
53
     *
54
     * @return \SimpleSAML\XMLSchema\Type\AnyURIValue
55
     */
56
    public function getValueType(): AnyURIValue
57
    {
58
        return $this->valueType;
59
    }
60
61
62
    /**
63
     * Get the valueType property.
64
     *
65
     * @return \SimpleSAML\XMLSchema\Type\AnyURIValue
66
     */
67
    public function getEncodingType(): AnyURIValue
68
    {
69
        return $this->encodingType;
70
    }
71
72
73
    /**
74
     * Convert XML into a class instance
75
     *
76
     * @param \DOMElement $xml The XML element we should load
77
     * @return static
78
     *
79
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
80
     *   If the qualified name of the supplied element is wrong
81
     */
82
    public static function fromXML(DOMElement $xml): static
83
    {
84
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
85
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
86
87
        return new static(
88
            StringValue::fromString($xml->textContent),
89
            self::getAttribute($xml, 'ValueType', AnyURIValue::class),
90
            self::getAttribute($xml, 'EncodingType', AnyURIValue::class),
91
            self::getAttributesNSFromXML($xml),
92
        );
93
    }
94
95
96
    /**
97
     * Convert this element to XML.
98
     *
99
     * @param \DOMElement|null $parent The element we should append this element to.
100
     * @return \DOMElement
101
     */
102
    public function toXML(?DOMElement $parent = null): DOMElement
103
    {
104
        $e = $this->instantiateParentElement($parent);
105
        $e->textContent = $this->getContent()->getValue();
106
107
        $e->setAttribute('ValueType', $this->getValueType()->getValue());
108
        $e->setAttribute('EncodingType', $this->getEncodingType()->getValue());
109
110
        foreach ($this->getAttributesNS() as $attr) {
111
            $attr->toXML($e);
112
        }
113
114
        return $e;
115
    }
116
}
117