WhiteSpace   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
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;
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\Schema\WhiteSpaceValue;
16
use SimpleSAML\XMLSchema\XML\Interface\FacetInterface;
17
18
use function array_pop;
19
20
/**
21
 * Class representing the whiteSpace element
22
 *
23
 * @package simplesamlphp/xml-common
24
 */
25
final class WhiteSpace extends AbstractFacet implements SchemaValidatableElementInterface, FacetInterface
26
{
27
    use SchemaValidatableElementTrait;
28
29
30
    /** @var string */
31
    public const LOCALNAME = 'whiteSpace';
32
33
34
    /**
35
     * WhiteSpace constructor
36
     *
37
     * @param \SimpleSAML\XMLSchema\Type\Schema\WhiteSpaceValue $value
38
     * @param \SimpleSAML\XMLSchema\Type\BooleanValue $fixed
39
     * @param \SimpleSAML\XMLSchema\XML\Annotation|null $annotation
40
     * @param \SimpleSAML\XMLSchema\Type\IDValue|null $id
41
     * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
42
     */
43
    final public function __construct(
44
        WhiteSpaceValue $value,
45
        ?BooleanValue $fixed = null,
46
        ?Annotation $annotation = null,
47
        ?IDValue $id = null,
48
        array $namespacedAttributes = [],
49
    ) {
50
        parent::__construct($value, $fixed, $annotation, $id, $namespacedAttributes);
51
    }
52
53
54
    /**
55
     * Create an instance of this object from its XML representation.
56
     *
57
     * @param \DOMElement $xml
58
     * @return static
59
     *
60
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
61
     *   if the qualified name of the supplied element is wrong
62
     */
63
    public static function fromXML(DOMElement $xml): static
64
    {
65
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
66
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
67
68
        $annotation = Annotation::getChildrenOfClass($xml);
69
        Assert::maxCount($annotation, 1, TooManyElementsException::class);
70
71
        return new static(
72
            self::getAttribute($xml, 'value', WhiteSpaceValue::class),
73
            self::getOptionalAttribute($xml, 'fixed', BooleanValue::class, null),
74
            array_pop($annotation),
75
            self::getOptionalAttribute($xml, 'id', IDValue::class, null),
76
            self::getAttributesNSFromXML($xml),
77
        );
78
    }
79
}
80