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

AbstractNoFixedFacet   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 13 1
A __construct() 0 7 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\XMLSchema\Exception\{InvalidDOMElementException, TooManyElementsException};
10
use SimpleSAML\XMLSchema\Type\{IDValue, StringValue};
11
use SimpleSAML\XMLSchema\Type\Interface\ValueTypeInterface;
12
13
use function array_pop;
14
15
/**
16
 * Abstract class representing the facet-type.
17
 *
18
 * @package simplesamlphp/xml-common
19
 */
20
abstract class AbstractNoFixedFacet extends AbstractFacet
21
{
22
    /**
23
     * NoFixedFacet constructor
24
     *
25
     * @param \SimpleSAML\XMLSchema\Type\Interface\ValueTypeInterface $value
26
     * @param \SimpleSAML\XMLSchema\XML\Annotation|null $annotation
27
     * @param \SimpleSAML\XMLSchema\Type\IDValue|null $id
28
     * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
29
     */
30
    final public function __construct(
31
        ValueTypeInterface $value,
32
        ?Annotation $annotation = null,
33
        ?IDValue $id = null,
34
        array $namespacedAttributes = [],
35
    ) {
36
        parent::__construct($value, null, $annotation, $id, $namespacedAttributes);
37
    }
38
39
40
    /**
41
     * Create an instance of this object from its XML representation.
42
     *
43
     * @param \DOMElement $xml
44
     * @return static
45
     *
46
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
47
     *   if the qualified name of the supplied element is wrong
48
     */
49
    public static function fromXML(DOMElement $xml): static
50
    {
51
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
52
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
53
54
        $annotation = Annotation::getChildrenOfClass($xml);
55
        Assert::maxCount($annotation, 1, TooManyElementsException::class);
56
57
        return new static(
58
            self::getAttribute($xml, 'value', StringValue::class),
59
            array_pop($annotation),
60
            self::getOptionalAttribute($xml, 'id', IDValue::class, null),
61
            self::getAttributesNSFromXML($xml),
62
        );
63
    }
64
}
65