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

WhiteSpace::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 5
dl 0
loc 8
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, SchemaValidatableElementTrait};
10
use SimpleSAML\XMLSchema\Exception\{InvalidDOMElementException, TooManyElementsException};
11
use SimpleSAML\XMLSchema\Type\{BooleanValue, IDValue};
12
use SimpleSAML\XMLSchema\Type\Schema\WhiteSpaceValue;
13
use SimpleSAML\XMLSchema\XML\Interface\FacetInterface;
14
15
use function array_pop;
16
17
/**
18
 * Class representing the whiteSpace element
19
 *
20
 * @package simplesamlphp/xml-common
21
 */
22
final class WhiteSpace extends AbstractFacet implements SchemaValidatableElementInterface, FacetInterface
23
{
24
    use SchemaValidatableElementTrait;
1 ignored issue
show
introduced by
The trait SimpleSAML\XML\SchemaValidatableElementTrait requires some properties which are not provided by SimpleSAML\XMLSchema\XML\WhiteSpace: $message, $line
Loading history...
25
26
    /** @var string */
27
    public const LOCALNAME = 'whiteSpace';
28
29
30
    /**
31
     * WhiteSpace constructor
32
     *
33
     * @param \SimpleSAML\XMLSchema\Type\Schema\WhiteSpaceValue $value
34
     * @param \SimpleSAML\XMLSchema\Type\BooleanValue $fixed
35
     * @param \SimpleSAML\XMLSchema\XML\Annotation|null $annotation
36
     * @param \SimpleSAML\XMLSchema\Type\IDValue|null $id
37
     * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
38
     */
39
    final public function __construct(
40
        WhiteSpaceValue $value,
41
        ?BooleanValue $fixed = null,
42
        ?Annotation $annotation = null,
43
        ?IDValue $id = null,
44
        array $namespacedAttributes = [],
45
    ) {
46
        parent::__construct($value, $fixed, $annotation, $id, $namespacedAttributes);
47
    }
48
49
50
    /**
51
     * Create an instance of this object from its XML representation.
52
     *
53
     * @param \DOMElement $xml
54
     * @return static
55
     *
56
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
57
     *   if the qualified name of the supplied element is wrong
58
     */
59
    public static function fromXML(DOMElement $xml): static
60
    {
61
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
62
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
63
64
        $annotation = Annotation::getChildrenOfClass($xml);
65
        Assert::maxCount($annotation, 1, TooManyElementsException::class);
66
67
        return new static(
68
            self::getAttribute($xml, 'value', WhiteSpaceValue::class),
69
            self::getOptionalAttribute($xml, 'fixed', BooleanValue::class, null),
70
            array_pop($annotation),
71
            self::getOptionalAttribute($xml, 'id', IDValue::class, null),
72
            self::getAttributesNSFromXML($xml),
73
        );
74
    }
75
}
76