Passed
Push — master ( 768e90...be6a83 )
by Tim
01:37
created

ProxySuccess::setProxyTicket()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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