AbstractEndpointType::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\fed;
6
7
use DOMElement;
8
use SimpleSAML\WSSecurity\Assert\Assert;
9
use SimpleSAML\WSSecurity\XML\wsa_200508\EndpointReference;
10
use SimpleSAML\XML\Exception\InvalidDOMElementException;
11
use SimpleSAML\XML\Exception\MissingElementException;
12
13
/**
14
 * An EndpointType
15
 *
16
 * @package simplesamlphp/ws-security
17
 */
18
abstract class AbstractEndpointType extends AbstractFedElement
19
{
20
    /**
21
     * ReferenceType constructor.
22
     *
23
     * @param array<\SimpleSAML\WSSecurity\XML\wsa_200508\EndpointReference> $endpointReference
24
     */
25
    final public function __construct(
26
        protected array $endpointReference,
27
    ) {
28
        Assert::minCount($endpointReference, 1, MissingElementException::class);
29
        Assert::allIsInstanceOf($endpointReference, EndpointReference::class);
30
    }
31
32
33
    /**
34
     * @return array<\SimpleSAML\WSSecurity\XML\wsa_200508\EndpointReference>
35
     */
36
    public function getEndpointReference(): array
37
    {
38
        return $this->endpointReference;
39
    }
40
41
42
    /*
43
     * Create an instance of this object from its XML representation.
44
     *
45
     * @param \DOMElement $xml
46
     * @return static
47
     *
48
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
49
     *   if the qualified name of the supplied element is wrong
50
     */
51
    public static function fromXML(DOMElement $xml): static
52
    {
53
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
54
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
55
56
        return new static(
57
            EndpointReference::getChildrenOfClass($xml),
58
        );
59
    }
60
61
62
    /**
63
     * Convert this element to XML.
64
     *
65
     * @param \DOMElement|null $parent The element we should append this element to.
66
     * @return \DOMElement
67
     */
68
    public function toXML(?DOMElement $parent = null): DOMElement
69
    {
70
        $e = $this->instantiateParentElement($parent);
71
72
        foreach ($this->getEndpointReference() as $endpointReference) {
73
            $endpointReference->toXML($e);
74
        }
75
76
        return $e;
77
    }
78
}
79