AttributeQuery::fromXML()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 14
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML11\XML\samlp;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\SAML11\Type\SAMLAnyURIValue;
10
use SimpleSAML\SAML11\XML\saml\AttributeDesignator;
11
use SimpleSAML\SAML11\XML\saml\Subject;
12
use SimpleSAML\XML\SchemaValidatableElementInterface;
13
use SimpleSAML\XML\SchemaValidatableElementTrait;
14
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
15
use SimpleSAML\XMLSchema\Exception\MissingElementException;
16
use SimpleSAML\XMLSchema\Exception\TooManyElementsException;
17
18
use function array_pop;
19
20
/**
21
 * Class representing a samlp:AttributeQuery element.
22
 *
23
 * @package simplesaml/saml11
24
 */
25
final class AttributeQuery extends AbstractAttributeQueryType implements SchemaValidatableElementInterface
26
{
27
    use SchemaValidatableElementTrait;
28
29
30
    /**
31
     * Convert XML into a AttributeQuery
32
     *
33
     * @param \DOMElement $xml The XML element we should load
34
     * @return static
35
     *
36
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
37
     *   if the qualified name of the supplied element is wrong
38
     */
39
    public static function fromXML(DOMElement $xml): static
40
    {
41
        Assert::same($xml->localName, 'AttributeQuery', InvalidDOMElementException::class);
42
        Assert::same($xml->namespaceURI, AttributeQuery::NS, InvalidDOMElementException::class);
43
44
        $resource = self::getOptionalAttribute($xml, 'Resource', SAMLAnyURIValue::class, null);
45
46
        $subject = Subject::getChildrenOfClass($xml);
47
        Assert::minCount($subject, 1, MissingElementException::class);
48
        Assert::maxCount($subject, 1, TooManyElementsException::class);
49
50
        $attributeDesignator = AttributeDesignator::getChildrenOfClass($xml);
51
52
        return new static(array_pop($subject), $resource, $attributeDesignator);
53
    }
54
}
55