FieldID::fromXML()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
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 22
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\TooManyElementsException;
13
14
/**
15
 * Class representing a dsig11:FieldID element.
16
 *
17
 * @package simplesaml/xml-security
18
 */
19
final class FieldID extends AbstractFieldIDType implements SchemaValidatableElementInterface
20
{
21
    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\FieldID: $message, $line
Loading history...
22
23
24
    /**
25
     * Convert XML into a FieldID element
26
     *
27
     * @param \DOMElement $xml The XML element we should load
28
     * @return static
29
     *
30
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
31
     *   If the qualified name of the supplied element is wrong
32
     */
33
    public static function fromXML(DOMElement $xml): static
34
    {
35
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
36
        Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
37
38
        $fieldId = array_merge(
39
            Prime::getChildrenOfClass($xml),
40
            TnB::getChildrenOfClass($xml),
41
            PnB::getChildrenOfClass($xml),
42
            GnB::getChildrenOfClass($xml),
43
            self::getChildElementsFromXML($xml),
44
        );
45
46
        Assert::count(
47
            $fieldId,
48
            1,
49
            'A <dsig11:FieldID> must contain exactly one child element',
50
            TooManyElementsException::class,
51
        );
52
53
        return new static(
54
            array_pop($fieldId),
55
        );
56
    }
57
}
58