KeyInfo   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 1
eloc 24
c 2
b 0
f 0
dl 0
loc 44
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 30 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\ds;
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\Type\IDValue;
13
use SimpleSAML\XMLSecurity\XML\dsig11\DEREncodedKeyValue;
14
15
use function array_merge;
16
17
/**
18
 * Class representing a ds:KeyInfo element.
19
 *
20
 * @package simplesamlphp/xml-security
21
 */
22
final class KeyInfo extends AbstractKeyInfoType 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\ds\KeyInfo: $message, $line
Loading history...
25
26
27
    /**
28
     * Convert XML into a KeyInfo
29
     *
30
     * @param \DOMElement $xml The XML element we should load
31
     * @return static
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, 'KeyInfo', InvalidDOMElementException::class);
39
        Assert::same($xml->namespaceURI, KeyInfo::NS, InvalidDOMElementException::class);
40
41
        $Id = self::getOptionalAttribute($xml, 'Id', IDValue::class, null);
42
43
        $keyName = KeyName::getChildrenOfClass($xml);
44
        $keyValue = KeyValue::getChildrenOfClass($xml);
45
        $retrievalMethod = RetrievalMethod::getChildrenOfClass($xml);
46
        $x509Data = X509Data::getChildrenOfClass($xml);
47
        $pgpData = PGPData::getChildrenOfClass($xml);
48
        $spkiData = SPKIData::getChildrenOfClass($xml);
49
        $mgmtData = MgmtData::getChildrenOfClass($xml);
50
        $derEncodedKeyValue = DEREncodedKeyValue::getChildrenOfClass($xml);
51
        $other = self::getChildElementsFromXML($xml);
52
53
        $info = array_merge(
54
            $keyName,
55
            $keyValue,
56
            $retrievalMethod,
57
            $x509Data,
58
            $pgpData,
59
            $spkiData,
60
            $mgmtData,
61
            $derEncodedKeyValue,
62
            $other,
63
        );
64
65
        return new static($info, $Id);
66
    }
67
}
68