Issues (341)

src/XMLSchema/XML/ReferencedGroup.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\NCNameValue;
14
use SimpleSAML\XMLSchema\Type\QNameValue;
15
use SimpleSAML\XMLSchema\XML\Interface\NestedParticleInterface;
16
use SimpleSAML\XMLSchema\XML\Interface\TypeDefParticleInterface;
17
18
use function array_pop;
19
20
/**
21
 * Class representing the group-element.
22
 *
23
 * @package simplesamlphp/xml-common
24
 */
25
final class ReferencedGroup extends AbstractReferencedGroup implements
26
    NestedParticleInterface,
27
    TypeDefParticleInterface
28
{
29
    public const string LOCALNAME = 'group';
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
        // Prohibited attributes
47
        $name = self::getOptionalAttribute($xml, 'name', NCNameValue::class, null);
48
        Assert::null($name, SchemaViolationException::class);
49
50
        $annotation = Annotation::getChildrenOfClass($xml);
51
        Assert::maxCount($annotation, 1, TooManyElementsException::class);
52
53
        return new static(
54
            reference: self::getAttribute($xml, 'ref', QNameValue::class),
55
            annotation: array_pop($annotation),
56
            id: self::getOptionalAttribute($xml, 'id', IDValue::class, null),
57
            namespacedAttributes: self::getAttributesNSFromXML($xml),
58
        );
59
    }
60
}
61