Passed
Pull Request — master (#18)
by Tim
02:12
created

X509SerialNumber::setSerial()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
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 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\ds;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Constants;
10
use SimpleSAML\XML\Exception\InvalidDOMElementException;
11
use SimpleSAML\XML\XMLStringElementTrait;
12
13
/**
14
 * Class representing a ds:X509SerialNumber element.
15
 *
16
 * @package simplesaml/xml-security
17
 */
18
final class X509SerialNumber extends AbstractDsElement
19
{
20
    use XMLStringElementTrait {
21
        toXML as parentToXML;
22
    }
23
24
25
    /**
26
     * Convert XML into a X509SerialNumber
27
     *
28
     * @param \DOMElement $xml The XML element we should load
29
     * @return self
30
     *
31
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
32
     *   If the qualified name of the supplied element is wrong
33
     */
34
    public static function fromXML(DOMElement $xml): object
35
    {
36
        Assert::same($xml->localName, 'X509SerialNumber', InvalidDOMElementException::class);
37
        Assert::same($xml->namespaceURI, X509SerialNumber::NS, InvalidDOMElementException::class);
38
        Assert::same($xml->getAttributeNS(Constants::NS_XSI, "type"), 'xs:integer');
39
40
        return new self($xml->textContent);
41
    }
42
43
44
    /**
45
     * Convert this X509SerialNumber element to XML.
46
     *
47
     * @param \DOMElement|null $parent The element we should append this X509SerialNumber element to.
48
     * @return \DOMElement
49
     */
50
    public function toXML(DOMElement $parent = null): DOMElement
51
    {
52
        $e = $this->parentToXML($parent);
53
        $e->setAttributeNS(Constants::NS_XSI, 'xsi:type', 'xs:integer');
54
55
        return $e;
56
    }
57
}
58