AuthorizationDecisionQuery   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

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

1 Method

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