TnB   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 12
c 1
b 0
f 0
dl 0
loc 30
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 16 1
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
15
use function array_pop;
16
17
/**
18
 * Class representing a dsig11:TnB element.
19
 *
20
 * @package simplesaml/xml-security
21
 */
22
final class TnB extends AbstractTnBFieldParamsType 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\dsig11\TnB: $message, $line
Loading history...
25
26
27
    /**
28
     * Convert XML into a TnB element
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, static::getLocalName(), InvalidDOMElementException::class);
39
        Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
40
41
        $k = K::getChildrenOfClass($xml);
42
        Assert::minCount($k, 1, MissingElementException::class);
43
        Assert::maxCount($k, 1, TooManyElementsException::class);
44
45
        $m = M::getChildrenOfClass($xml);
46
        Assert::minCount($m, 1, MissingElementException::class);
47
        Assert::maxCount($m, 1, TooManyElementsException::class);
48
49
        return new static(
50
            array_pop($m),
51
            array_pop($k),
52
        );
53
    }
54
}
55