Passed
Pull Request — master (#6)
by Tim
02:14
created

AbstractParam::toXML()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\wsdl;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Exception\SchemaViolationException;
10
11
/**
12
 * Abstract class representing the tParam type.
13
 *
14
 * @package simplesamlphp/ws-security
15
 */
16
abstract class AbstractParam extends AbstractExtensibleAttributesDocumented
17
{
18
    /**
19
     * Initialize a wsdl:tParam
20
     *
21
     * @param string $message
22
     * @param string|null $name
23
     * @param \SimpleSAML\XML\Attribute[] $attributes
24
     */
25
    public function __construct(
26
        protected string $message,
27
        protected ?string $name = null,
28
        array $attributes = [],
29
    ) {
30
        Assert::validQName($message, SchemaViolationException::class);
31
        Assert::nullOrValidNCName($name, SchemaViolationException::class);
32
33
        parent::__construct($attributes);
34
    }
35
36
37
    /**
38
     * Collect the value of the name-property.
39
     *
40
     * @return string|null
41
     */
42
    public function getName(): ?string
43
    {
44
        return $this->name;
45
    }
46
47
48
    /**
49
     * Collect the value of the message-property.
50
     *
51
     * @return string
52
     */
53
    public function getMessage(): string
54
    {
55
        return $this->message;
56
    }
57
58
59
    /**
60
     * Test if an object, at the state it's in, would produce an empty XML-element
61
     *
62
     * @return bool
63
     */
64
    public function isEmptyElement(): bool
65
    {
66
        // Upstream abstract elements can be empty, but this one cannot
67
        return false;
68
    }
69
70
71
    /**
72
     * Convert this tParam to XML.
73
     *
74
     * @param \DOMElement|null $parent The element we are converting to XML.
75
     * @return \DOMElement The XML element after adding the data corresponding to this tParam.
76
     */
77
    public function toXML(DOMElement $parent = null): DOMElement
78
    {
79
        $e = parent::toXML($parent);
80
81
        if ($this->getName() !== null) {
82
            $e->setAttribute('name', $this->getName());
83
        }
84
85
        $e->setAttribute('message', $this->getMessage());
86
87
        return $e;
88
    }
89
}
90