Passed
Pull Request — master (#24)
by Tim
01:53
created

AbstractProxies::getProxy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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\MissingElementException;
11
12
/**
13
 * Class for CAS proxies
14
 *
15
 * @package simplesamlphp/xml-cas
16
 */
17
abstract class AbstractProxies 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
    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 this Proxies to XML.
48
     *
49
     * @param \DOMElement|null $parent The element we should append this Proxies to.
50
     * @return \DOMElement
51
     */
52
    public function toXML(?DOMElement $parent = null): DOMElement
53
    {
54
        $e = $this->instantiateParentElement($parent);
55
56
        foreach ($this->getProxy() as $proxy) {
57
            $proxy->toXML($e);
58
        }
59
60
        return $e;
61
    }
62
}
63