Issues (341)

src/XMLSchema/XML/NarrowMaxMinElement.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\TooManyElementsException;
11
use SimpleSAML\XMLSchema\Type\BooleanValue;
12
use SimpleSAML\XMLSchema\Type\IDValue;
13
use SimpleSAML\XMLSchema\Type\NCNameValue;
14
use SimpleSAML\XMLSchema\Type\QNameValue;
15
use SimpleSAML\XMLSchema\Type\Schema\BlockSetValue;
16
use SimpleSAML\XMLSchema\Type\Schema\FormChoiceValue;
17
use SimpleSAML\XMLSchema\Type\Schema\MaxOccursValue;
18
use SimpleSAML\XMLSchema\Type\Schema\MinOccursValue;
19
use SimpleSAML\XMLSchema\Type\StringValue;
20
use SimpleSAML\XMLSchema\XML\Interface\NestedParticleInterface;
21
22
use function array_merge;
23
use function array_pop;
24
25
/**
26
 * Class representing the local narrowMaxMin-element.
27
 *
28
 * @package simplesamlphp/xml-common
29
 */
30
final class NarrowMaxMinElement extends AbstractNarrowMaxMin implements NestedParticleInterface
31
{
32
    public const string LOCALNAME = 'element';
0 ignored issues
show
A parse error occurred: Syntax error, unexpected T_STRING, expecting '=' on line 32 at column 24
Loading history...
33
34
35
    /**
36
     * Create an instance of this object from its XML representation.
37
     *
38
     * @param \DOMElement $xml
39
     * @return static
40
     *
41
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
42
     *   if the qualified name of the supplied element is wrong
43
     */
44
    public static function fromXML(DOMElement $xml): static
45
    {
46
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
47
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
48
49
        $annotation = Annotation::getChildrenOfClass($xml);
50
        Assert::maxCount($annotation, 1, TooManyElementsException::class);
51
52
        // The local type
53
        $localSimpleType = LocalSimpleType::getChildrenOfClass($xml);
54
        Assert::maxCount($localSimpleType, 1, TooManyElementsException::class);
55
56
        $localComplexType = LocalComplexType::getChildrenOfClass($xml);
57
        Assert::maxCount($localComplexType, 1, TooManyElementsException::class);
58
59
        $localType = array_merge($localSimpleType, $localComplexType);
60
        Assert::maxCount($localType, 1, TooManyElementsException::class);
61
62
        // The identity constraint
63
        $key = Key::getChildrenOfClass($xml);
64
        Assert::maxCount($key, 1, TooManyElementsException::class);
65
66
        $keyref = Keyref::getChildrenOfClass($xml);
67
        Assert::maxCount($keyref, 1, TooManyElementsException::class);
68
69
        $unique = Unique::getChildrenOfClass($xml);
70
        Assert::maxCount($unique, 1, TooManyElementsException::class);
71
72
        $identityConstraint = array_merge($key, $keyref, $unique);
73
74
        return new static(
75
            self::getOptionalAttribute($xml, 'name', NCNameValue::class, null),
76
            self::getOptionalAttribute($xml, 'ref', QNameValue::class, null),
77
            array_pop($localType),
78
            $identityConstraint,
79
            self::getOptionalAttribute($xml, 'type', QNameValue::class, null),
80
            self::getOptionalAttribute($xml, 'minOccurs', MinOccursValue::class, null),
81
            self::getOptionalAttribute($xml, 'maxOccurs', MaxOccursValue::class, null),
82
            self::getOptionalAttribute($xml, 'default', StringValue::class, null),
83
            self::getOptionalAttribute($xml, 'fixed', StringValue::class, null),
84
            self::getOptionalAttribute($xml, 'nillable', BooleanValue::class, null),
85
            self::getOptionalAttribute($xml, 'block', BlockSetValue::class, null),
86
            self::getOptionalAttribute($xml, 'form', FormChoiceValue::class, null),
87
            array_pop($annotation),
88
            self::getOptionalAttribute($xml, 'id', IDValue::class, null),
89
            self::getAttributesNSFromXML($xml),
90
        );
91
    }
92
}
93