KeyLength::toXML()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\xenc11;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
10
use SimpleSAML\XMLSchema\Type\PositiveIntegerValue;
11
12
use function strval;
13
14
/**
15
 * Class representing a xenc11:KeyLength element.
16
 *
17
 * @package simplesamlphp/xml-security
18
 */
19
final class KeyLength extends AbstractXenc11Element
20
{
21
    /**
22
     * @param \SimpleSAML\XMLSchema\Type\PositiveIntegerValue $keyLength
23
     */
24
    public function __construct(
25
        protected PositiveIntegerValue $keyLength,
26
    ) {
27
    }
28
29
30
    /**
31
     * @return \SimpleSAML\XMLSchema\Type\PositiveIntegerValue
32
     */
33
    public function getKeyLength(): PositiveIntegerValue
34
    {
35
        return $this->keyLength;
36
    }
37
38
39
    /**
40
     * Convert XML into a class instance
41
     *
42
     * @param \DOMElement $xml The XML element we should load
43
     * @return static
44
     *
45
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
46
     *   If the qualified name of the supplied element is wrong
47
     */
48
    public static function fromXML(DOMElement $xml): static
49
    {
50
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
51
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
52
53
        return new static(
54
            PositiveIntegerValue::fromString($xml->textContent),
55
        );
56
    }
57
58
59
    /**
60
     * Convert this element to XML.
61
     *
62
     * @param \DOMElement|null $parent The element we should append this element to.
63
     * @return \DOMElement
64
     */
65
    public function toXML(?DOMElement $parent = null): DOMElement
66
    {
67
        $e = $this->instantiateParentElement($parent);
68
        $e->textContent = strval($this->getKeyLength());
69
70
        return $e;
71
    }
72
}
73