ECKeyValue   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 15
c 1
b 0
f 0
dl 0
loc 34
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 20 1
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\SchemaValidatableElementInterface;
10
use SimpleSAML\XML\SchemaValidatableElementTrait;
11
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12
use SimpleSAML\XMLSchema\Exception\MissingElementException;
13
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
14
use SimpleSAML\XMLSchema\Type\IDValue;
15
16
use function array_pop;
17
18
/**
19
 * Class representing a dsig11:ECKeyValue element.
20
 *
21
 * @package simplesaml/xml-security
22
 */
23
final class ECKeyValue extends AbstractECKeyValueType implements SchemaValidatableElementInterface
24
{
25
    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...
26
27
28
    /**
29
     * Convert XML into a ECKeyValue element
30
     *
31
     * @param \DOMElement $xml The XML element we should load
32
     * @return static
33
     *
34
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
35
     *   If the qualified name of the supplied element is wrong
36
     */
37
    public static function fromXML(DOMElement $xml): static
38
    {
39
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
40
        Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
41
42
        $publicKey = PublicKey::getChildrenOfClass($xml);
43
        Assert::minCount($publicKey, 1, MissingElementException::class);
44
        Assert::maxCount($publicKey, 1, TooManyElementsException::class);
45
46
        $ecParameters = ECParameters::getChildrenOfClass($xml);
47
        Assert::maxCount($ecParameters, 1, TooManyElementsException::class);
48
49
        $namedCurve = NamedCurve::getChildrenOfClass($xml);
50
        Assert::maxCount($namedCurve, 1, TooManyElementsException::class);
51
52
        return new static(
53
            array_pop($publicKey),
54
            self::getOptionalAttribute($xml, 'Id', IDValue::class, null),
55
            array_pop($ecParameters),
56
            array_pop($namedCurve),
57
        );
58
    }
59
}
60