AbstractServiceNameType::toXML()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 14
rs 10
cc 3
nc 4
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\wsa_200408;
6
7
use DOMElement;
8
use SimpleSAML\WSSecurity\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
 * Class representing WS-addressing ServiceNameType.
17
 *
18
 * You can extend the class without extending the constructor. Then you can use the methods available and the class
19
 * will generate an element with the same name as the extending class
20
 * (e.g. \SimpleSAML\WSSecurity\wsa\ServiceName).
21
 *
22
 * @package simplesamlphp/ws-security
23
 */
24
abstract class AbstractServiceNameType extends AbstractWsaElement
25
{
26
    use ExtendableAttributesTrait;
27
    use QNameElementTrait;
28
29
    /** The namespace-attribute for the xs:anyElement element */
30
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
31
32
33
    /**
34
     * AbstractServiceNameType constructor.
35
     *
36
     * @param string $value The QName.
37
     * @param string|null $portName The PortName.
38
     * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
0 ignored issues
show
Bug introduced by
The type SimpleSAML\WSSecurity\XML\wsa_200408\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
39
     */
40
    final public function __construct(
41
        string $value,
42
        protected ?string $portName = null,
43
        array $namespacedAttributes = [],
44
    ) {
45
        Assert::nullOrValidNCName($portName, SchemaViolationException::class);
46
47
        $this->setContent($value);
48
        $this->setAttributesNS($namespacedAttributes);
49
    }
50
51
52
    /**
53
     * Get the value of the portName property
54
     */
55
    public function getPortName(): ?string
56
    {
57
        return $this->portName;
58
    }
59
60
61
    /**
62
     * Convert XML into a class instance
63
     *
64
     * @param \DOMElement $xml The XML element we should load
65
     * @return static
66
     *
67
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
68
     *   If the qualified name of the supplied element is wrong
69
     */
70
    public static function fromXML(DOMElement $xml): static
71
    {
72
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
73
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
74
75
        return new static(
76
            $xml->textContent,
77
            self::getOptionalAttribute($xml, 'PortName', null),
78
            self::getAttributesNSFromXML($xml),
79
        );
80
    }
81
82
83
    /**
84
     * Convert this element to XML.
85
     *
86
     * @param \DOMElement|null $parent The element we should append this element to.
87
     * @return \DOMElement
88
     */
89
    public function toXML(?DOMElement $parent = null): DOMElement
90
    {
91
        $e = $this->instantiateParentElement($parent);
92
        $e->textContent = $this->getContent();
93
94
        if ($this->getPortName() !== null) {
95
            $e->setAttribute('PortName', $this->getPortName());
96
        }
97
98
        foreach ($this->getAttributesNS() as $attr) {
99
            $attr->toXML($e);
100
        }
101
102
        return $e;
103
    }
104
}
105