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

ProxySuccess::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 0
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
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
/**
13
 * Class for CAS proxySuccess
14
 *
15
 * @package simplesamlphp/xml-cas
16
 */
17
final class ProxySuccess extends AbstractProxySuccess
18
{
19
    /**
20
     * Initialize an ProxySuccess element.
21
     *
22
     * @param \DOMElement $xml The XML element we should load.
23
     * @return static
24
     *
25
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
26
     *   if the qualified name of the supplied element is wrong
27
     * @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException
28
     *   if the supplied element is missing any of the mandatory attributes
29
     */
30
    public static function fromXML(DOMElement $xml): static
31
    {
32
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
33
        Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
34
35
        $proxyTicket = ProxyTicket::getChildrenOfClass($xml);
36
        Assert::count(
37
            $proxyTicket,
38
            1,
39
            'Exactly one <cas:proxyTicket> must be specified.',
40
            MissingElementException::class,
41
        );
42
43
        return new static($proxyTicket[0]);
44
    }
45
}
46