Passed
Pull Request — master (#61)
by Tim
02:17
created

MaxExclusive::fromXML()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
nc 1
nop 1
dl 0
loc 14
rs 9.9332
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSchema\XML\xs;
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\Builtin\{BooleanValue, IDValue, StringValue};
12
13
use function array_pop;
14
15
/**
16
 * Class representing the maxExclusive element
17
 *
18
 * @package simplesamlphp/xml-common
19
 */
20
final class MaxExclusive extends AbstractFacet implements SchemaValidatableElementInterface, FacetInterface
21
{
22
    use SchemaValidatableElementTrait;
1 ignored issue
show
introduced by
The trait SimpleSAML\XML\SchemaValidatableElementTrait requires some properties which are not provided by SimpleSAML\XMLSchema\XML\xs\MaxExclusive: $message, $line
Loading history...
23
24
    /** @var string */
25
    public const LOCALNAME = 'maxExclusive';
26
27
28
    /**
29
     * Create an instance of this object from its XML representation.
30
     *
31
     * @param \DOMElement $xml
32
     * @return static
33
     *
34
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
35
     *   if the qualified name of the supplied element is wrong
36
     */
37
    public static function fromXML(DOMElement $xml): static
38
    {
39
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
40
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
41
42
        $annotation = Annotation::getChildrenOfClass($xml);
43
        Assert::maxCount($annotation, 1, TooManyElementsException::class);
44
45
        return new static(
46
            self::getAttribute($xml, 'value', StringValue::class),
47
            self::getOptionalAttribute($xml, 'fixed', BooleanValue::class, null),
48
            array_pop($annotation),
49
            self::getOptionalAttribute($xml, 'id', IDValue::class, null),
50
            self::getAttributesNSFromXML($xml),
51
        );
52
    }
53
}
54