Passed
Push — master ( fb3113...2f4a0c )
by Tim
02:23
created

AbstractServiceNameType::getEndpointName()   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\WSSecurity\XML\wsaw;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10
use SimpleSAML\XML\Exception\SchemaViolationException;
11
use SimpleSAML\XML\ExtendableAttributesTrait;
12
use SimpleSAML\XML\QNameElementTrait;
13
use SimpleSAML\XML\XsNamespace as NS;
14
15
/**
16
 * Abstract class defining the ServiceNameType type
17
 *
18
 * @package simplesamlphp/ws-security
19
 */
20
abstract class AbstractServiceNameType extends AbstractWsawElement
21
{
22
    use ExtendableAttributesTrait;
23
    use QNameElementTrait;
24
25
    /** The namespace-attribute for the xs:anyAttribute element */
26
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
27
28
29
    /**
30
     * AbstractServiceName constructor
31
     *
32
     * @param string $value
33
     * @param string|null $endpointName
34
     * @param \SimpleSAML\XML\Attribute[] $namespacedAttributes
35
     */
36
    public function __construct(
37
        string $value,
38
        protected ?string $endpointName = null,
39
        array $namespacedAttributes = [],
40
    ) {
41
        Assert::nullOrValidNCName($endpointName, SchemaViolationException::class);
42
43
        $this->setContent($value);
44
        $this->setAttributesNS($namespacedAttributes);
45
    }
46
47
48
    /**
49
     * Collect the value of the endpointName property.
50
     *
51
     * @return string|null
52
     */
53
    public function getEndpointName(): ?string
54
    {
55
        return $this->endpointName;
56
    }
57
58
59
    /**
60
     * Convert this ServiceNameType to XML.
61
     *
62
     * @param \DOMElement|null $parent The element we should append this class to.
63
     * @return \DOMElement The XML element after adding the data corresponding to this ServiceNameType.
64
     */
65
    public function toXML(DOMElement $parent = null): DOMElement
66
    {
67
        $e = $this->instantiateParentElement($parent);
68
        $e->textContent = $this->getContent();
69
70
        if ($this->getEndpointName() !== null) {
71
            $e->setAttribute('EndpointName', $this->getEndpointName());
72
        }
73
74
        foreach ($this->getAttributesNS() as $attr) {
75
            $attr->toXML($e);
76
        }
77
78
        return $e;
79
    }
80
}
81