Passed
Push — master ( 9ffc8a...24ef5c )
by Tim
07:04
created

X509SerialNumber::__construct()   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;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\XMLStringElementTrait requires some properties which are not provided by SimpleSAML\XMLSecurity\XML\ds\X509SerialNumber: $localName, $namespaceURI
Loading history...
21
22
23
    /**
24
     * @param string $content
25
     */
26
    public function __construct(string $content)
27
    {
28
        $this->setContent($content);
29
    }
30
31
32
    /**
33
     * Convert XML into a X509SerialNumber
34
     *
35
     * @param \DOMElement $xml The XML element we should load
36
     * @return self
37
     *
38
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
39
     *   If the qualified name of the supplied element is wrong
40
     */
41
    public static function fromXML(DOMElement $xml): object
42
    {
43
        Assert::same($xml->localName, 'X509SerialNumber', InvalidDOMElementException::class);
44
        Assert::same($xml->namespaceURI, X509SerialNumber::NS, InvalidDOMElementException::class);
45
        Assert::same($xml->getAttributeNS(Constants::NS_XSI, "type"), 'xs:integer');
46
47
        return new self($xml->textContent);
48
    }
49
50
51
    /**
52
     * Convert this X509SerialNumber element to XML.
53
     *
54
     * @param \DOMElement|null $parent The element we should append this X509SerialNumber element to.
55
     * @return \DOMElement
56
     */
57
    public function toXML(DOMElement $parent = null): DOMElement
58
    {
59
        $e = $this->instantiateParentElement($parent);
60
        $e->textContent = $this->content;
61
        $e->setAttributeNS(Constants::NS_XSI, 'xsi:type', 'xs:integer');
62
63
        return $e;
64
    }
65
}
66