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