Issues (341)

src/XMLSchema/XML/WhiteSpace.php (1 issue)

Labels
Severity
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
    public const string LOCALNAME = 'whiteSpace';
0 ignored issues
show
A parse error occurred: Syntax error, unexpected T_STRING, expecting '=' on line 30 at column 24
Loading history...
31
32
33
    /**
34
     * WhiteSpace constructor
35
     *
36
     * @param \SimpleSAML\XMLSchema\Type\Schema\WhiteSpaceValue $value
37
     * @param \SimpleSAML\XMLSchema\Type\BooleanValue $fixed
38
     * @param \SimpleSAML\XMLSchema\XML\Annotation|null $annotation
39
     * @param \SimpleSAML\XMLSchema\Type\IDValue|null $id
40
     * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
41
     */
42
    final public function __construct(
43
        WhiteSpaceValue $value,
44
        ?BooleanValue $fixed = null,
45
        ?Annotation $annotation = null,
46
        ?IDValue $id = null,
47
        array $namespacedAttributes = [],
48
    ) {
49
        parent::__construct($value, $fixed, $annotation, $id, $namespacedAttributes);
50
    }
51
52
53
    /**
54
     * Create an instance of this object from its XML representation.
55
     *
56
     * @param \DOMElement $xml
57
     * @return static
58
     *
59
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
60
     *   if the qualified name of the supplied element is wrong
61
     */
62
    public static function fromXML(DOMElement $xml): static
63
    {
64
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
65
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
66
67
        $annotation = Annotation::getChildrenOfClass($xml);
68
        Assert::maxCount($annotation, 1, TooManyElementsException::class);
69
70
        return new static(
71
            self::getAttribute($xml, 'value', WhiteSpaceValue::class),
72
            self::getOptionalAttribute($xml, 'fixed', BooleanValue::class, null),
73
            array_pop($annotation),
74
            self::getOptionalAttribute($xml, 'id', IDValue::class, null),
75
            self::getAttributesNSFromXML($xml),
76
        );
77
    }
78
}
79