TotalDigits::fromXML()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 1
dl 0
loc 14
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSchema\XML;
6
7
use DOMElement;
8
use SimpleSAML\XML\Assert\Assert;
9
use SimpleSAML\XML\SchemaValidatableElementInterface;
10
use SimpleSAML\XML\SchemaValidatableElementTrait;
11
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
13
use SimpleSAML\XMLSchema\Type\BooleanValue;
14
use SimpleSAML\XMLSchema\Type\IDValue;
15
use SimpleSAML\XMLSchema\Type\PositiveIntegerValue;
16
use SimpleSAML\XMLSchema\XML\Interface\FacetInterface;
17
18
use function array_pop;
19
20
/**
21
 * Class representing the totalDigits element
22
 *
23
 * @package simplesamlphp/xml-common
24
 */
25
final class TotalDigits extends AbstractNumFacet implements SchemaValidatableElementInterface, FacetInterface
26
{
27
    use SchemaValidatableElementTrait;
28
29
30
    /** @var string */
31
    public const LOCALNAME = 'totalDigits';
32
33
34
    /**
35
     * Create an instance of this object from its XML representation.
36
     *
37
     * @param \DOMElement $xml
38
     * @return static
39
     *
40
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
41
     *   if the qualified name of the supplied element is wrong
42
     */
43
    public static function fromXML(DOMElement $xml): static
44
    {
45
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
46
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
47
48
        $annotation = Annotation::getChildrenOfClass($xml);
49
        Assert::maxCount($annotation, 1, TooManyElementsException::class);
50
51
        return new static(
52
            self::getAttribute($xml, 'value', PositiveIntegerValue::class),
53
            self::getOptionalAttribute($xml, 'fixed', BooleanValue::class, null),
54
            array_pop($annotation),
55
            self::getOptionalAttribute($xml, 'id', IDValue::class, null),
56
            self::getAttributesNSFromXML($xml),
57
        );
58
    }
59
}
60