Passed
Push — master ( a7f2e0...7bcc2b )
by Tim
02:25
created

ECParameters::fromXML()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 25
nc 1
nop 1
dl 0
loc 34
rs 9.52
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\dsig11;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10
use SimpleSAML\XML\Exception\MissingElementException;
11
use SimpleSAML\XML\Exception\TooManyElementsException;
12
13
use function array_pop;
14
15
/**
16
 * Class representing a dsig11:ECParameters element.
17
 *
18
 * @package simplesaml/xml-security
19
 */
20
final class ECParameters extends AbstractECParametersType
21
{
22
    /**
23
     * Convert XML into a ECParameters element
24
     *
25
     * @param \DOMElement $xml The XML element we should load
26
     * @return static
27
     *
28
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
29
     *   If the qualified name of the supplied element is wrong
30
     */
31
    public static function fromXML(DOMElement $xml): static
32
    {
33
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
34
        Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
35
36
        $fieldId = FieldID::getChildrenOfClass($xml);
37
        Assert::minCount($fieldId, 1, MissingElementException::class);
38
        Assert::maxCount($fieldId, 1, TooManyElementsException::class);
39
40
        $curve = Curve::getChildrenOfClass($xml);
41
        Assert::minCount($curve, 1, MissingElementException::class);
42
        Assert::maxCount($curve, 1, TooManyElementsException::class);
43
44
        $base = Base::getChildrenOfClass($xml);
45
        Assert::minCount($base, 1, MissingElementException::class);
46
        Assert::maxCount($base, 1, TooManyElementsException::class);
47
48
        $order = Order::getChildrenOfClass($xml);
49
        Assert::minCount($order, 1, MissingElementException::class);
50
        Assert::maxCount($order, 1, TooManyElementsException::class);
51
52
        $coFactor = CoFactor::getChildrenOfClass($xml);
53
        Assert::maxCount($coFactor, 1, TooManyElementsException::class);
54
55
        $validationData = ValidationData::getChildrenOfClass($xml);
56
        Assert::maxCount($validationData, 1, TooManyElementsException::class);
57
58
        return new static(
59
            array_pop($fieldId),
60
            array_pop($curve),
61
            array_pop($base),
62
            array_pop($order),
63
            array_pop($coFactor),
64
            array_pop($validationData),
65
        );
66
    }
67
}
68