Issues (81)

src/XML/dsig11/FieldID.php (1 issue)

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