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

ECKeyValue::fromXML()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 14
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 20
rs 9.7998
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
use SimpleSAML\XML\SchemaValidatableElementInterface;
13
use SimpleSAML\XML\SchemaValidatableElementTrait;
14
15
use function array_pop;
16
17
/**
18
 * Class representing a dsig11:ECKeyValue element.
19
 *
20
 * @package simplesaml/xml-security
21
 */
22
final class ECKeyValue extends AbstractECKeyValueType implements SchemaValidatableElementInterface
23
{
24
    use SchemaValidatableElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\SchemaValidatableElementTrait requires some properties which are not provided by SimpleSAML\XMLSecurity\XML\dsig11\ECKeyValue: $message, $line
Loading history...
25
26
    /**
27
     * Convert XML into a ECKeyValue element
28
     *
29
     * @param \DOMElement $xml The XML element we should load
30
     * @return static
31
     *
32
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
33
     *   If the qualified name of the supplied element is wrong
34
     */
35
    public static function fromXML(DOMElement $xml): static
36
    {
37
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
38
        Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
39
40
        $publicKey = PublicKey::getChildrenOfClass($xml);
41
        Assert::minCount($publicKey, 1, MissingElementException::class);
42
        Assert::maxCount($publicKey, 1, TooManyElementsException::class);
43
44
        $ecParameters = ECParameters::getChildrenOfClass($xml);
45
        Assert::maxCount($ecParameters, 1, TooManyElementsException::class);
46
47
        $namedCurve = NamedCurve::getChildrenOfClass($xml);
48
        Assert::maxCount($namedCurve, 1, TooManyElementsException::class);
49
50
        return new static(
51
            array_pop($publicKey),
52
            self::getOptionalAttribute($xml, 'Id', null),
53
            array_pop($ecParameters),
54
            array_pop($namedCurve),
55
        );
56
    }
57
}
58