Completed
Push — master ( f72cfb...4ef12f )
by Tim
21s queued 18s
created

Sequence   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 30 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\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
11
use SimpleSAML\XMLSchema\Type\Builtin\{IDValue, NCNameValue, QNameValue};
12
use SimpleSAML\XMLSchema\Type\{MaxOccursValue, MinOccursValue};
13
14
use function array_merge;
15
use function array_pop;
16
17
/**
18
 * Class representing the sequence-element.
19
 *
20
 * @package simplesamlphp/xml-common
21
 */
22
final class Sequence extends AbstractExplicitGroup implements
23
    NestedParticleInterface,
24
    ParticleInterface,
25
    SchemaValidatableElementInterface,
26
    TypeDefParticleInterface
27
{
28
    use SchemaValidatableElementTrait;
1 ignored issue
show
introduced by
The trait SimpleSAML\XML\SchemaValidatableElementTrait requires some properties which are not provided by SimpleSAML\XMLSchema\XML\xs\Sequence: $message, $line
Loading history...
29
30
    /** @var string */
31
    public const LOCALNAME = 'sequence';
32
33
34
    /**
35
     * Create an instance of this object from its XML representation.
36
     *
37
     * @param \DOMElement $xml
38
     * @return static
39
     *
40
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
41
     *   if the qualified name of the supplied element is wrong
42
     */
43
    public static function fromXML(DOMElement $xml): static
44
    {
45
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
46
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
47
48
        // Prohibited attributes
49
        $name = self::getOptionalAttribute($xml, 'name', NCNameValue::class, null);
50
        Assert::null($name, SchemaViolationException::class);
51
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
        $any = Any::getChildrenOfClass($xml);
59
        $choice = Choice::getChildrenOfClass($xml);
60
        $localElement = LocalElement::getChildrenOfClass($xml);
61
        $referencedGroup = ReferencedGroup::getChildrenOfClass($xml);
62
        $sequence = Sequence::getChildrenOfClass($xml);
63
64
        $particles = array_merge($any, $choice, $localElement, $referencedGroup, $sequence);
65
66
        return new static(
67
            self::getOptionalAttribute($xml, 'minOccurs', MinOccursValue::class, null),
68
            self::getOptionalAttribute($xml, 'maxOccurs', MaxOccursValue::class, null),
69
            $particles,
70
            array_pop($annotation),
71
            self::getOptionalAttribute($xml, 'id', IDValue::class, null),
72
            self::getAttributesNSFromXML($xml),
73
        );
74
    }
75
}
76