PnB   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 26 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:PnB element.
19
 *
20
 * @package simplesaml/xml-security
21
 */
22
final class PnB extends AbstractPnBFieldParamsType 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\PnB: $message, $line
Loading history...
25
26
27
    /**
28
     * Convert XML into a PnB 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
        $k1 = K1::getChildrenOfClass($xml);
42
        Assert::minCount($k1, 1, MissingElementException::class);
43
        Assert::maxCount($k1, 1, TooManyElementsException::class);
44
45
        $k2 = K2::getChildrenOfClass($xml);
46
        Assert::minCount($k2, 1, MissingElementException::class);
47
        Assert::maxCount($k2, 1, TooManyElementsException::class);
48
49
        $k3 = K3::getChildrenOfClass($xml);
50
        Assert::minCount($k3, 1, MissingElementException::class);
51
        Assert::maxCount($k3, 1, TooManyElementsException::class);
52
53
        $m = M::getChildrenOfClass($xml);
54
        Assert::minCount($m, 1, MissingElementException::class);
55
        Assert::maxCount($m, 1, TooManyElementsException::class);
56
57
        return new static(
58
            array_pop($m),
59
            array_pop($k1),
60
            array_pop($k2),
61
            array_pop($k3),
62
        );
63
    }
64
}
65