Passed
Pull Request — master (#64)
by Tim
03:03 queued 01:02
created

FieldID::fromXML()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 20
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 27
rs 9.6
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\Exception\InvalidDOMElementException;
10
use SimpleSAML\XML\Exception\MissingElementException;
11
use SimpleSAML\XML\Exception\TooManyElementsException;
12
use SimpleSAML\XML\SchemaValidatableElementInterface;
13
use SimpleSAML\XML\SchemaValidatableElementTrait;
14
15
/**
16
 * Class representing a dsig11:FieldID element.
17
 *
18
 * @package simplesaml/xml-security
19
 */
20
final class FieldID extends AbstractFieldIDType implements SchemaValidatableElementInterface
21
{
22
    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...
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\XML\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
        $prime = Prime::getChildrenOfClass($xml);
39
        Assert::minCount($prime, 1, MissingElementException::class);
40
        Assert::maxCount($prime, 1, TooManyElementsException::class);
41
42
        $tnb = TnB::getChildrenOfClass($xml);
43
        Assert::minCount($tnb, 1, MissingElementException::class);
44
        Assert::maxCount($tnb, 1, TooManyElementsException::class);
45
46
        $pnb = PnB::getChildrenOfClass($xml);
47
        Assert::minCount($pnb, 1, MissingElementException::class);
48
        Assert::maxCount($pnb, 1, TooManyElementsException::class);
49
50
        $gnb = GnB::getChildrenOfClass($xml);
51
        Assert::minCount($gnb, 1, MissingElementException::class);
52
        Assert::maxCount($gnb, 1, TooManyElementsException::class);
53
54
        return new static(
55
            array_pop($prime),
56
            array_pop($tnb),
57
            array_pop($pnb),
58
            array_pop($gnb),
59
            self::getChildElementsFromXML($xml),
60
        );
61
    }
62
}
63