Issues (341)

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