Issues (341)

src/XMLSchema/XML/AnyAttribute.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\IDValue;
14
use SimpleSAML\XMLSchema\Type\Schema\NamespaceListValue;
15
use SimpleSAML\XMLSchema\Type\Schema\ProcessContentsValue;
16
17
use function array_pop;
18
19
/**
20
 * Class representing the anyAttribute element
21
 *
22
 * @package simplesamlphp/xml-common
23
 */
24
final class AnyAttribute extends AbstractWildcard implements SchemaValidatableElementInterface
25
{
26
    use SchemaValidatableElementTrait;
27
28
29
    public const string LOCALNAME = 'anyAttribute';
0 ignored issues
show
A parse error occurred: Syntax error, unexpected T_STRING, expecting '=' on line 29 at column 24
Loading history...
30
31
32
    /**
33
     * Create an instance of this object from its XML representation.
34
     *
35
     * @param \DOMElement $xml
36
     * @return static
37
     *
38
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
39
     *   if the qualified name of the supplied element is wrong
40
     */
41
    public static function fromXML(DOMElement $xml): static
42
    {
43
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
44
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
45
46
        $annotation = Annotation::getChildrenOfClass($xml);
47
        Assert::maxCount($annotation, 1, TooManyElementsException::class);
48
49
        return new static(
50
            self::getOptionalAttribute($xml, 'namespace', NamespaceListValue::class, null),
51
            self::getOptionalAttribute($xml, 'processContents', ProcessContentsValue::class, null),
52
            array_pop($annotation),
53
            self::getOptionalAttribute($xml, 'id', IDValue::class, null),
54
            self::getAttributesNSFromXML($xml),
55
        );
56
    }
57
}
58