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

AbstractPart   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 16
c 1
b 0
f 0
dl 0
loc 90
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getElement() 0 3 1
A __construct() 0 11 1
A getType() 0 3 1
A isEmptyElement() 0 4 1
A toXML() 0 15 3
A getName() 0 3 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 tPart type.
13
 *
14
 * @package simplesamlphp/ws-security
15
 */
16
abstract class AbstractPart extends AbstractExtensibleAttributesDocumented
17
{
18
    /**
19
     * Initialize a wsdl:tPart
20
     *
21
     * @param string $name
22
     * @param string|null $element
23
     * @param string|null $type
24
     * @param \SimpleSAML\XML\Attribute[] $attributes
25
     */
26
    public function __construct(
27
        protected string $name,
28
        protected ?string $element,
29
        protected ?string $type,
30
        array $attributes = [],
31
    ) {
32
        Assert::validNCName($name, SchemaViolationException::class);
33
        Assert::nullOrValidQName($element, SchemaViolationException::class);
34
        Assert::nullOrValidQName($type, SchemaViolationException::class);
35
36
        parent::__construct($attributes);
37
    }
38
39
40
    /**
41
     * Collect the value of the name-property.
42
     *
43
     * @return string
44
     */
45
    public function getName(): string
46
    {
47
        return $this->name;
48
    }
49
50
51
    /**
52
     * Collect the value of the element-property.
53
     *
54
     * @return string|null
55
     */
56
    public function getElement(): ?string
57
    {
58
        return $this->element;
59
    }
60
61
62
    /**
63
     * Collect the value of the type-property.
64
     *
65
     * @return string|null
66
     */
67
    public function getType(): ?string
68
    {
69
        return $this->type;
70
    }
71
72
73
    /**
74
     * Test if an object, at the state it's in, would produce an empty XML-element
75
     *
76
     * @return bool
77
     */
78
    public function isEmptyElement(): bool
79
    {
80
        // Upstream abstract elements can be empty, but this one cannot
81
        return false;
82
    }
83
84
85
    /**
86
     * Convert this tPart to XML.
87
     *
88
     * @param \DOMElement|null $parent The element we are converting to XML.
89
     * @return \DOMElement The XML element after adding the data corresponding to this tPart.
90
     */
91
    public function toXML(DOMElement $parent = null): DOMElement
92
    {
93
        $e = parent::toXML($parent);
94
95
        $e->setAttribute('name', $this->getName());
96
97
        if ($this->getElement() !== null) {
98
            $e->setAttribute('element', $this->getElement());
99
        }
100
101
        if ($this->getType() !== null) {
102
            $e->setAttribute('type', $this->getType());
103
        }
104
105
        return $e;
106
    }
107
}
108