Proxies   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 14
dl 0
loc 68
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getProxy() 0 3 1
A fromXML() 0 7 1
A toXML() 0 9 2
A __construct() 0 6 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\CAS\Constants as C;
10
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
11
use SimpleSAML\XMLSchema\Exception\MissingElementException;
12
13
/**
14
 * Class for CAS proxies
15
 *
16
 * @package simplesamlphp/cas
17
 */
18
final class Proxies extends AbstractCasElement
19
{
20
    /** @var string */
21
    final public const LOCALNAME = 'proxies';
22
23
24
    /**
25
     * Initialize a Proxies element.
26
     *
27
     * @param \SimpleSAML\CAS\XML\Proxy[] $proxy
28
     */
29
    final public function __construct(
30
        protected array $proxy = [],
31
    ) {
32
        Assert::maxCount($proxy, C::UNBOUNDED_LIMIT);
33
        Assert::allIsInstanceOf($proxy, Proxy::class);
34
        Assert::minCount($proxy, 1, 'Missing at least one Proxy in Proxies.', MissingElementException::class);
35
    }
36
37
38
    /**
39
     * @return \SimpleSAML\CAS\XML\Proxy[]
40
     */
41
    public function getProxy(): array
42
    {
43
        return $this->proxy;
44
    }
45
46
47
    /**
48
     * Convert XML into a Proxies-element
49
     *
50
     * @param \DOMElement $xml The XML element we should load
51
     * @return static
52
     *
53
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
54
     *  if the qualified name of the supplied element is wrong
55
     * @throws \SimpleSAML\XMLSchema\Exception\MissingElementException
56
     *  if one of the mandatory child-elements is missing
57
     * @throws \SimpleSAML\XMLSchema\Exception\TooManyElementsException
58
     *  if too many child-elements of a type are specified
59
     */
60
    public static function fromXML(DOMElement $xml): static
61
    {
62
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
63
        Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
64
65
        return new static(
66
            Proxy::getChildrenOfClass($xml),
67
        );
68
    }
69
70
71
    /**
72
     * Convert this Proxies to XML.
73
     *
74
     * @param \DOMElement|null $parent The element we should append this Proxies to.
75
     * @return \DOMElement
76
     */
77
    public function toXML(?DOMElement $parent = null): DOMElement
78
    {
79
        $e = $this->instantiateParentElement($parent);
80
81
        foreach ($this->getProxy() as $proxy) {
82
            $proxy->toXML($e);
83
        }
84
85
        return $e;
86
    }
87
}
88