Issues (341)

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