Passed
Pull Request — master (#24)
by Tim
01:55
created

AuthenticationSuccess::getAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\CAS\XML;
6
7
use DOMElement;
8
use SimpleSAML\CAS\Assert\Assert;
9
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
10
use SimpleSAML\XMLSchema\Exception\MissingElementException;
11
12
use function array_pop;
13
14
/**
15
 * Class for CAS authenticationSuccess
16
 *
17
 * @package simplesamlphp/xml-cas
18
 */
19
final class AuthenticationSuccess extends AbstractAuthenticationSuccess
20
{
21
    /**
22
     * Convert XML into a cas:authenticationSuccess-element
23
     *
24
     * @param \DOMElement $xml The XML element we should load
25
     * @return static
26
     *
27
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
28
     *   if the qualified name of the supplied element is wrong
29
     * @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException
30
     *   if the supplied element is missing one of the mandatory attributes
31
     */
32
    public static function fromXML(DOMElement $xml): static
33
    {
34
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
35
        Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
36
37
        $user = User::getChildrenOfClass($xml);
38
        Assert::count(
39
            $user,
40
            1,
41
            'Exactly one <cas:user> must be specified.',
42
            MissingElementException::class,
43
        );
44
45
        $attributes = Attributes::getChildrenOfClass($xml);
46
        Assert::count(
47
            $attributes,
48
            1,
49
            'Exactly one <cas:attributes> must be specified.',
50
            MissingElementException::class,
51
        );
52
53
        $proxyGrantingTicket = ProxyGrantingTicket::getChildrenOfClass($xml);
54
        $proxies = Proxies::getChildrenOfClass($xml);
55
56
        return new static(
57
            $user[0],
58
            $attributes[0],
59
            array_pop($proxyGrantingTicket),
60
            array_pop($proxies),
61
        );
62
    }
63
}
64