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

WhiteSpace   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 51
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

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