Passed
Pull Request — master (#61)
by Tim
02:17
created

ReferencedAttributeGroup   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 32
rs 10
c 1
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 17 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSchema\XML\xs;
6
7
use DOMElement;
8
use SimpleSAML\XML\Assert\Assert;
9
use SimpleSAML\XMLSchema\Exception\{InvalidDOMElementException, SchemaViolationException, TooManyElementsException};
10
use SimpleSAML\XMLSchema\Type\Builtin\{IDValue, QNameValue};
11
12
use function array_pop;
13
14
/**
15
 * Class representing the attributeGroup-element.
16
 *
17
 * @package simplesamlphp/xml-common
18
 */
19
final class ReferencedAttributeGroup extends AbstractReferencedAttributeGroup
20
{
21
    /** @var string */
22
    public const LOCALNAME = 'attributeGroup';
23
24
25
    /**
26
     * Create an instance of this object from its XML representation.
27
     *
28
     * @param \DOMElement $xml
29
     * @return static
30
     *
31
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
32
     *   if the qualified name of the supplied element is wrong
33
     */
34
    public static function fromXML(DOMElement $xml): static
35
    {
36
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
37
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
38
39
        // Prohibited attributes
40
        $name = self::getOptionalAttribute($xml, 'name', QNameValue::class, null);
41
        Assert::null($name, SchemaViolationException::class);
42
43
        $annotation = Annotation::getChildrenOfClass($xml);
44
        Assert::maxCount($annotation, 1, TooManyElementsException::class);
45
46
        return new static(
47
            self::getAttribute($xml, 'ref', QNameValue::class),
48
            array_pop($annotation),
49
            self::getOptionalAttribute($xml, 'id', IDValue::class, null),
50
            self::getAttributesNSFromXML($xml),
51
        );
52
    }
53
}
54