Issues (341)

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