ProxySuccess   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 14
dl 0
loc 67
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toXML() 0 7 1
A getProxyTicket() 0 3 1
A __construct() 0 3 1
A fromXML() 0 14 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/cas
16
 */
17
final class ProxySuccess extends AbstractResponse
18
{
19
    /** @var string */
20
    final public const LOCALNAME = 'proxySuccess';
21
22
23
    /**
24
     * Initialize a cas:proxySuccess element
25
     *
26
     * @param \SimpleSAML\CAS\XML\ProxyTicket $proxyTicket
27
     */
28
    final public function __construct(
29
        protected ProxyTicket $proxyTicket,
30
    ) {
31
    }
32
33
34
    /**
35
     * @return \SimpleSAML\CAS\XML\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\XMLSchema\Exception\InvalidDOMElementException
50
     *   if the qualified name of the supplied element is wrong
51
     * @throws \SimpleSAML\XMLSchema\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, static::getLocalName(), InvalidDOMElementException::class);
57
        Assert::same($xml->namespaceURI, static::getNamespaceURI(), 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($proxyTicket[0]);
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