Issues (81)

src/XML/dsig11/ValidationData.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
use SimpleSAML\XMLSchema\Type\AnyURIValue;
12
13
use function array_pop;
14
15
/**
16
 * Class representing a dsig11:ValidationData element.
17
 *
18
 * @package simplesaml/xml-security
19
 */
20
final class ValidationData extends AbstractECValidationDataType implements SchemaValidatableElementInterface
21
{
22
    use SchemaValidatableElementTrait;
0 ignored issues
show
The trait SimpleSAML\XML\SchemaValidatableElementTrait requires some properties which are not provided by SimpleSAML\XMLSecurity\XML\dsig11\ValidationData: $message, $line
Loading history...
23
24
    /**
25
     * Convert XML into a ValidationData element
26
     *
27
     * @param \DOMElement $xml The XML element we should load
28
     * @return static
29
     *
30
     * @throws \SimpleSAML\XMLSchema\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
        $seed = Seed::getChildrenOfClass($xml);
39
        Assert::minCount($seed, 1, MissingElementException::class);
40
        Assert::maxCount($seed, 1, TooManyElementsException::class);
41
42
        return new static(
43
            array_pop($seed),
44
            self::getAttribute($xml, 'hashAlgorithm', AnyURIValue::class),
45
        );
46
    }
47
}
48