Issues (81)

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