Passed
Push — master ( 8413b2...00f101 )
by Tim
02:19
created

TotalDigits   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 14 1
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, SchemaValidatableElementTrait};
10
use SimpleSAML\XMLSchema\Exception\{InvalidDOMElementException, TooManyElementsException};
11
use SimpleSAML\XMLSchema\Type\{BooleanValue, IDValue, PositiveIntegerValue};
12
use SimpleSAML\XMLSchema\XML\Interface\FacetInterface;
13
14
use function array_pop;
15
16
/**
17
 * Class representing the totalDigits element
18
 *
19
 * @package simplesamlphp/xml-common
20
 */
21
final class TotalDigits extends AbstractNumFacet implements SchemaValidatableElementInterface, FacetInterface
22
{
23
    use SchemaValidatableElementTrait;
1 ignored issue
show
introduced by
The trait SimpleSAML\XML\SchemaValidatableElementTrait requires some properties which are not provided by SimpleSAML\XMLSchema\XML\TotalDigits: $message, $line
Loading history...
24
25
    /** @var string */
26
    public const LOCALNAME = 'totalDigits';
27
28
29
    /**
30
     * Create an instance of this object from its XML representation.
31
     *
32
     * @param \DOMElement $xml
33
     * @return static
34
     *
35
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
36
     *   if the qualified name of the supplied element is wrong
37
     */
38
    public static function fromXML(DOMElement $xml): static
39
    {
40
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
41
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
42
43
        $annotation = Annotation::getChildrenOfClass($xml);
44
        Assert::maxCount($annotation, 1, TooManyElementsException::class);
45
46
        return new static(
47
            self::getAttribute($xml, 'value', PositiveIntegerValue::class),
48
            self::getOptionalAttribute($xml, 'fixed', BooleanValue::class, null),
49
            array_pop($annotation),
50
            self::getOptionalAttribute($xml, 'id', IDValue::class, null),
51
            self::getAttributesNSFromXML($xml),
52
        );
53
    }
54
}
55