ProxySuccess::toXML()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
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, MissingElementException};
10
11
/**
12
 * Class for CAS proxySuccess
13
 *
14
 * @package simplesamlphp/cas
15
 */
16
final class ProxySuccess extends AbstractResponse
17
{
18
    /** @var string */
19
    final public const LOCALNAME = 'proxySuccess';
20
21
22
    /**
23
     * Initialize a cas:proxySuccess element
24
     *
25
     * @param \SimpleSAML\CAS\XML\ProxyTicket $proxyTicket
26
     */
27
    final public function __construct(
28
        protected ProxyTicket $proxyTicket,
29
    ) {
30
    }
31
32
33
    /**
34
     * @return \SimpleSAML\CAS\XML\ProxyTicket
35
     */
36
    public function getProxyTicket(): ProxyTicket
37
    {
38
        return $this->proxyTicket;
39
    }
40
41
42
    /**
43
     * Initialize an ProxySuccess element.
44
     *
45
     * @param \DOMElement $xml The XML element we should load.
46
     * @return static
47
     *
48
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
49
     *   if the qualified name of the supplied element is wrong
50
     * @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException
51
     *   if the supplied element is missing any of the mandatory attributes
52
     */
53
    public static function fromXML(DOMElement $xml): static
54
    {
55
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
56
        Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
57
58
        $proxyTicket = ProxyTicket::getChildrenOfClass($xml);
59
        Assert::count(
60
            $proxyTicket,
61
            1,
62
            'Exactly one <cas:proxyTicket> must be specified.',
63
            MissingElementException::class,
64
        );
65
66
        return new static($proxyTicket[0]);
67
    }
68
69
70
    /**
71
     * Convert this ProxySuccess to XML.
72
     *
73
     * @param \DOMElement|null $parent The element we should append to.
74
     * @return \DOMElement This ProxySuccess-element.
75
     */
76
    public function toXML(?DOMElement $parent = null): DOMElement
77
    {
78
        $e = $this->instantiateParentElement($parent);
79
80
        $this->getProxyTicket()->toXML($e);
81
82
        return $e;
83
    }
84
}
85