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

AbstractBinding   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 15
c 1
b 0
f 0
dl 0
loc 87
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A getType() 0 3 1
A getOperation() 0 3 1
A isEmptyElement() 0 4 1
A toXML() 0 12 2
A __construct() 0 11 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 tBinding type.
13
 *
14
 * @package simplesamlphp/ws-security
15
 */
16
abstract class AbstractBinding extends AbstractExtensibleDocumented
17
{
18
    /**
19
     * Initialize a wsdl:tBinding
20
     *
21
     * @param string $name
22
     * @param string $type
23
     * @param \SimpleSAML\WSSecurity\XML\wsdl\BindingOperation[] $operation
24
     * @param \SimpleSAML\XML\Chunk[] $elements
25
     */
26
    public function __construct(
27
        protected string $name,
28
        protected string $type,
29
        protected array $operation = [],
30
        array $elements = [],
31
    ) {
32
        Assert::validNCName($name, SchemaViolationException::class);
33
        Assert::validQName($type, SchemaViolationException::class);
34
        Assert::allIsInstanceOf($operation, BindingOperation::class, SchemaViolationException::class);
35
36
        parent::__construct($elements);
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 type-property.
53
     *
54
     * @return string
55
     */
56
    public function getType(): string
57
    {
58
        return $this->type;
59
    }
60
61
62
    /**
63
     * Collect the value of the operation-property.
64
     *
65
     * @return \SimpleSAML\WSSecurity\XML\wsdl\BindingOperation[]
66
     */
67
    public function getOperation(): array
68
    {
69
        return $this->operation;
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 tBinding 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 tBinding.
90
     */
91
    public function toXML(DOMElement $parent = null): DOMElement
92
    {
93
        $e = parent::toXML($parent);
94
95
        $e->setAttribute('name', $this->getName());
96
        $e->setAttribute('type', $this->getType());
97
98
        foreach ($this->getOperation() as $operation) {
99
            $operation->toXML($e);
100
        }
101
102
        return $e;
103
    }
104
}
105