Passed
Push — master ( faa376...c7ca4c )
by Tim
17:29 queued 14:52
created

ComplexRestriction   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

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