K1::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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