Passed
Branch feature/php8.3 (4d3b0a)
by Tim
17:15
created

MaxInclusive   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 12
dl 0
loc 32
rs 10
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\StringValue;
16
use SimpleSAML\XMLSchema\XML\Interface\FacetInterface;
17
18
use function array_pop;
19
20
/**
21
 * Class representing the maxInclusive element
22
 *
23
 * @package simplesamlphp/xml-common
24
 */
25
final class MaxInclusive extends AbstractFacet implements SchemaValidatableElementInterface, FacetInterface
26
{
27
    use SchemaValidatableElementTrait;
28
29
30
    public const string LOCALNAME = 'maxInclusive';
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting '=' on line 30 at column 24
Loading history...
31
32
33
    /**
34
     * Create an instance of this object from its XML representation.
35
     *
36
     * @param \DOMElement $xml
37
     * @return static
38
     *
39
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
40
     *   if the qualified name of the supplied element is wrong
41
     */
42
    public static function fromXML(DOMElement $xml): static
43
    {
44
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
45
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
46
47
        $annotation = Annotation::getChildrenOfClass($xml);
48
        Assert::maxCount($annotation, 1, TooManyElementsException::class);
49
50
        return new static(
51
            self::getAttribute($xml, 'value', StringValue::class),
52
            self::getOptionalAttribute($xml, 'fixed', BooleanValue::class, null),
53
            array_pop($annotation),
54
            self::getOptionalAttribute($xml, 'id', IDValue::class, null),
55
            self::getAttributesNSFromXML($xml),
56
        );
57
    }
58
}
59