AttributeQuery   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 27
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 27
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 14 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, Subject};
11
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
12
use SimpleSAML\XMLSchema\Exception\{InvalidDOMElementException, MissingElementException, TooManyElementsException};
13
14
use function array_pop;
15
16
/**
17
 * Class representing a samlp:AttributeQuery element.
18
 *
19
 * @package simplesaml/saml11
20
 */
21
final class AttributeQuery extends AbstractAttributeQueryType implements SchemaValidatableElementInterface
22
{
23
    use SchemaValidatableElementTrait;
24
25
    /**
26
     * Convert XML into a AttributeQuery
27
     *
28
     * @param \DOMElement $xml The XML element we should load
29
     * @return static
30
     *
31
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
32
     *   if the qualified name of the supplied element is wrong
33
     */
34
    public static function fromXML(DOMElement $xml): static
35
    {
36
        Assert::same($xml->localName, 'AttributeQuery', InvalidDOMElementException::class);
37
        Assert::same($xml->namespaceURI, AttributeQuery::NS, InvalidDOMElementException::class);
38
39
        $resource = self::getOptionalAttribute($xml, 'Resource', SAMLAnyURIValue::class, null);
40
41
        $subject = Subject::getChildrenOfClass($xml);
42
        Assert::minCount($subject, 1, MissingElementException::class);
43
        Assert::maxCount($subject, 1, TooManyElementsException::class);
44
45
        $attributeDesignator = AttributeDesignator::getChildrenOfClass($xml);
46
47
        return new static(array_pop($subject), $resource, $attributeDesignator);
48
    }
49
}
50