ECKeyValue::fromXML()   A
last analyzed

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\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;
26
27
28
    /**
29
     * Convert XML into a ECKeyValue element
30
     *
31
     * @param \DOMElement $xml The XML element we should load
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::getNamespaceURI(), InvalidDOMElementException::class);
40
41
        $publicKey = PublicKey::getChildrenOfClass($xml);
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSecurity\XML\dsig11\PublicKey was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
42
        Assert::minCount($publicKey, 1, MissingElementException::class);
43
        Assert::maxCount($publicKey, 1, TooManyElementsException::class);
44
45
        $ecParameters = ECParameters::getChildrenOfClass($xml);
46
        Assert::maxCount($ecParameters, 1, TooManyElementsException::class);
47
48
        $namedCurve = NamedCurve::getChildrenOfClass($xml);
49
        Assert::maxCount($namedCurve, 1, TooManyElementsException::class);
50
51
        return new static(
52
            array_pop($publicKey),
53
            self::getOptionalAttribute($xml, 'Id', IDValue::class, null),
54
            array_pop($ecParameters),
55
            array_pop($namedCurve),
56
        );
57
    }
58
}
59