Issues (341)

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