AuthenticationQuery   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

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

1 Method

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