ValidationData   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 12 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
use SimpleSAML\XMLSchema\Type\AnyURIValue;
15
16
use function array_pop;
17
18
/**
19
 * Class representing a dsig11:ValidationData element.
20
 *
21
 * @package simplesaml/xml-security
22
 */
23
final class ValidationData extends AbstractECValidationDataType implements SchemaValidatableElementInterface
24
{
25
    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\ValidationData: $message, $line
Loading history...
26
27
28
    /**
29
     * Convert XML into a ValidationData element
30
     *
31
     * @param \DOMElement $xml The XML element we should load
32
     * @return static
33
     *
34
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
35
     *   If the qualified name of the supplied element is wrong
36
     */
37
    public static function fromXML(DOMElement $xml): static
38
    {
39
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
40
        Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
41
42
        $seed = Seed::getChildrenOfClass($xml);
43
        Assert::minCount($seed, 1, MissingElementException::class);
44
        Assert::maxCount($seed, 1, TooManyElementsException::class);
45
46
        return new static(
47
            array_pop($seed),
48
            self::getAttribute($xml, 'hashAlgorithm', AnyURIValue::class),
49
        );
50
    }
51
}
52