Passed
Pull Request — master (#4)
by Tim
02:02
created

AuthenticationQuery   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 7
c 1
b 0
f 0
dl 0
loc 23
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\XML\saml\Subject;
10
use SimpleSAML\XML\Exception\InvalidDOMElementException;
11
use SimpleSAML\XML\Exception\MissingElementException;
12
use SimpleSAML\XML\Exception\TooManyElementsException;
13
14
use function array_pop;
15
16
/**
17
 * Class representing a samlp:AuthenticationQuery element.
18
 *
19
 * @package simplesaml/saml11
20
 */
21
final class AuthenticationQuery extends AbstractAuthenticationQueryType
22
{
23
    /**
24
     * Convert XML into a AuthenticationQuery
25
     *
26
     * @param \DOMElement $xml The XML element we should load
27
     * @return static
28
     *
29
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
30
     *   if the qualified name of the supplied element is wrong
31
     */
32
    public static function fromXML(DOMElement $xml): static
33
    {
34
        Assert::same($xml->localName, 'AuthenticationQuery', InvalidDOMElementException::class);
35
        Assert::same($xml->namespaceURI, AuthenticationQuery::NS, InvalidDOMElementException::class);
36
37
        $authenticationMethod = self::getAttribute($xml, 'AuthenticationMethod');
38
39
        $subject = Subject::getChildrenOfClass($xml);
40
        Assert::minCount($subject, 1, MissingElementException::class);
41
        Assert::maxCount($subject, 1, TooManyElementsException::class);
42
43
        return new static(array_pop($subject), $authenticationMethod);
44
    }
45
}
46