Passed
Branch master (c7ca4c)
by Tim
16:17 queued 14:33
created

All   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 18
dl 0
loc 47
rs 10
c 0
b 0
f 0
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\XML\SchemaValidatableElementInterface;
10
use SimpleSAML\XML\SchemaValidatableElementTrait;
11
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
13
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
14
use SimpleSAML\XMLSchema\Type\IDValue;
15
use SimpleSAML\XMLSchema\Type\NCNameValue;
16
use SimpleSAML\XMLSchema\Type\QNameValue;
17
use SimpleSAML\XMLSchema\Type\Schema\MaxOccursValue;
18
use SimpleSAML\XMLSchema\Type\Schema\MinOccursValue;
19
use SimpleSAML\XMLSchema\XML\Interface\ParticleInterface;
20
use SimpleSAML\XMLSchema\XML\Interface\TypeDefParticleInterface;
21
22
use function array_pop;
23
24
/**
25
 * Class representing the all-element.
26
 *
27
 * @package simplesamlphp/xml-common
28
 */
29
final class All extends AbstractAll implements
30
    ParticleInterface,
31
    SchemaValidatableElementInterface,
32
    TypeDefParticleInterface
33
{
34
    use SchemaValidatableElementTrait;
35
36
37
    public const string LOCALNAME = 'all';
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting '=' on line 37 at column 24
Loading history...
38
39
40
    /**
41
     * Create an instance of this object from its XML representation.
42
     *
43
     * @param \DOMElement $xml
44
     * @return static
45
     *
46
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
47
     *   if the qualified name of the supplied element is wrong
48
     */
49
    public static function fromXML(DOMElement $xml): static
50
    {
51
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
52
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
53
54
        // Prohibited attributes
55
        $name = self::getOptionalAttribute($xml, 'name', NCNameValue::class, null);
56
        Assert::null($name, SchemaViolationException::class);
57
58
        $ref = self::getOptionalAttribute($xml, 'ref', QNameValue::class, null);
59
        Assert::null($ref, SchemaViolationException::class);
60
61
        // The annotation
62
        $annotation = Annotation::getChildrenOfClass($xml);
63
        Assert::maxCount($annotation, 1, TooManyElementsException::class);
64
65
        // The content
66
        $narrowMaxMin = NarrowMaxMinElement::getChildrenOfClass($xml);
67
68
        return new static(
69
            self::getOptionalAttribute($xml, 'minCount', MinOccursValue::class, null),
70
            self::getOptionalAttribute($xml, 'maxCount', MaxOccursValue::class, null),
71
            $narrowMaxMin,
72
            annotation: array_pop($annotation),
73
            id: self::getOptionalAttribute($xml, 'id', IDValue::class, null),
74
            namespacedAttributes: self::getAttributesNSFromXML($xml),
75
        );
76
    }
77
}
78