Completed
Push — master ( da4b66...3ae217 )
by Tim
19s queued 15s
created

AttributeQuery   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 8
c 1
b 0
f 0
dl 0
loc 25
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\XML\saml\AttributeDesignator;
10
use SimpleSAML\SAML11\XML\saml\Subject;
11
use SimpleSAML\XML\Exception\InvalidDOMElementException;
12
use SimpleSAML\XML\Exception\MissingElementException;
13
use SimpleSAML\XML\Exception\TooManyElementsException;
14
15
use function array_pop;
16
17
/**
18
 * Class representing a samlp:AttributeQuery element.
19
 *
20
 * @package simplesaml/saml11
21
 */
22
final class AttributeQuery extends AbstractAttributeQueryType
23
{
24
    /**
25
     * Convert XML into a AttributeQuery
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, 'AttributeQuery', InvalidDOMElementException::class);
36
        Assert::same($xml->namespaceURI, AttributeQuery::NS, InvalidDOMElementException::class);
37
38
        $resource = self::getOptionalAttribute($xml, 'Resource', null);
39
40
        $subject = Subject::getChildrenOfClass($xml);
41
        Assert::minCount($subject, 1, MissingElementException::class);
42
        Assert::maxCount($subject, 1, TooManyElementsException::class);
43
44
        $attributeDesignator = AttributeDesignator::getChildrenOfClass($xml);
45
46
        return new static(array_pop($subject), $resource, $attributeDesignator);
47
    }
48
}
49