AbstractEndpointReferenceType   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 173
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
eloc 48
dl 0
loc 173
rs 10
c 1
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getPortType() 0 3 1
A __construct() 0 11 1
A fromXML() 0 34 1
A getReferenceParameters() 0 3 1
A getServiceName() 0 3 1
A getReferenceProperties() 0 3 1
A toXML() 0 22 4
A getAddress() 0 3 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\MissingElementException;
11
use SimpleSAML\XML\Exception\TooManyElementsException;
12
use SimpleSAML\XML\ExtendableAttributesTrait;
13
use SimpleSAML\XML\ExtendableElementTrait;
14
use SimpleSAML\XML\XsNamespace as NS;
15
16
use function array_pop;
17
use function sprintf;
18
19
/**
20
 * Class representing WS-addressing EndpointReferenceType.
21
 *
22
 * You can extend the class without extending the constructor. Then you can use the methods available
23
 * and the class will generate an element with the same name as the extending class
24
 * (e.g. \SimpleSAML\WSSecurity\wsa\EndpointReference).
25
 *
26
 * @package simplesamlphp/ws-security
27
 */
28
abstract class AbstractEndpointReferenceType extends AbstractWsaElement
29
{
30
    use ExtendableAttributesTrait;
31
    use ExtendableElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\ExtendableElementTrait requires some properties which are not provided by SimpleSAML\WSSecurity\XM...ctEndpointReferenceType: $namespaceURI, $localName, $childNodes
Loading history...
32
33
    /** The namespace-attribute for the xs:any element */
34
    public const XS_ANY_ELT_NAMESPACE = NS::OTHER;
35
36
    /** The namespace-attribute for the xs:anyAttribute element */
37
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
38
39
40
    /**
41
     * EndpointReferenceType constructor.
42
     *
43
     * @param \SimpleSAML\WSSecurity\XML\wsa_200408\Address $address
44
     * @param \SimpleSAML\WSSecurity\XML\wsa_200408\ReferenceProperties|null $referenceProperties
45
     * @param \SimpleSAML\WSSecurity\XML\wsa_200408\ReferenceParameters|null $referenceParameters
46
     * @param \SimpleSAML\WSSecurity\XML\wsa_200408\PortType|null $portType
47
     * @param \SimpleSAML\WSSecurity\XML\wsa_200408\ServiceName|null $serviceName
48
     * @param \SimpleSAML\XML\SerializableElementInterface[] $children
49
     * @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...
50
     *
51
     * @throws \SimpleSAML\Assert\AssertionFailedException
52
     */
53
    final public function __construct(
54
        protected Address $address,
55
        protected ?ReferenceProperties $referenceProperties = null,
56
        protected ?ReferenceParameters $referenceParameters = null,
57
        protected ?PortType $portType = null,
58
        protected ?ServiceName $serviceName = null,
59
        array $children = [],
60
        array $namespacedAttributes = [],
61
    ) {
62
        $this->setElements($children);
63
        $this->setAttributesNS($namespacedAttributes);
64
    }
65
66
67
    /**
68
     * Collect the value of the address property.
69
     *
70
     * @return \SimpleSAML\WSSecurity\XML\wsa_200408\Address
71
     */
72
    public function getAddress(): Address
73
    {
74
        return $this->address;
75
    }
76
77
78
    /**
79
     * Collect the value of the referenceProperties property.
80
     *
81
     * @return \SimpleSAML\WSSecurity\XML\wsa_200408\ReferenceProperties|null
82
     */
83
    public function getReferenceProperties(): ?ReferenceProperties
84
    {
85
        return $this->referenceProperties;
86
    }
87
88
89
    /**
90
     * Collect the value of the referenceParameters property.
91
     *
92
     * @return \SimpleSAML\WSSecurity\XML\wsa_200408\ReferenceParameters|null
93
     */
94
    public function getReferenceParameters(): ?ReferenceParameters
95
    {
96
        return $this->referenceParameters;
97
    }
98
99
100
    /**
101
     * Collect the value of the portType property.
102
     *
103
     * @return \SimpleSAML\WSSecurity\XML\wsa_200408\PortType|null
104
     */
105
    public function getPortType(): ?PortType
106
    {
107
        return $this->portType;
108
    }
109
110
111
    /**
112
     * Collect the value of the serviceName property.
113
     *
114
     * @return \SimpleSAML\WSSecurity\XML\wsa_200408\ServiceName|null
115
     */
116
    public function getServiceName(): ?ServiceName
117
    {
118
        return $this->serviceName;
119
    }
120
121
122
    /**
123
     * Initialize an EndpointReferenceType.
124
     *
125
     * Note: this method cannot be used when extending this class, if the constructor has a different signature.
126
     *
127
     * @param \DOMElement $xml The XML element we should load.
128
     * @return static
129
     *
130
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
131
     *   if the qualified name of the supplied element is wrong
132
     * @throws \SimpleSAML\XML\Exception\MissingAttributeException
133
     *   if the supplied element is missing any of the mandatory attributes
134
     */
135
    public static function fromXML(DOMElement $xml): static
136
    {
137
        $qualifiedName = static::getClassName(static::class);
138
        Assert::eq(
139
            $xml->localName,
140
            $qualifiedName,
141
            sprintf('Unexpected name for endpoint reference: %s. Expected: %s.', $xml->localName, $qualifiedName),
142
            InvalidDOMElementException::class,
143
        );
144
145
        $address = Address::getChildrenOfClass($xml);
146
        Assert::minCount($address, 1, MissingElementException::class);
147
        Assert::maxCount($address, 1, TooManyElementsException::class);
148
149
        $referenceProperties = ReferenceProperties::getChildrenOfClass($xml);
150
        Assert::maxCount($referenceProperties, 1, TooManyElementsException::class);
151
152
        $referenceParameters = ReferenceParameters::getChildrenOfClass($xml);
153
        Assert::maxCount($referenceParameters, 1, TooManyElementsException::class);
154
155
        $portType = PortType::getChildrenOfClass($xml);
156
        Assert::maxCount($portType, 1, TooManyElementsException::class);
157
158
        $serviceName = ServiceName::getChildrenOfClass($xml);
159
        Assert::maxCount($serviceName, 1, TooManyElementsException::class);
160
161
        return new static(
162
            array_pop($address),
163
            array_pop($referenceProperties),
164
            array_pop($referenceParameters),
165
            array_pop($portType),
166
            array_pop($serviceName),
167
            self::getChildElementsFromXML($xml),
168
            self::getAttributesNSFromXML($xml),
169
        );
170
    }
171
172
173
    /**
174
     * Add this endpoint reference to an XML element.
175
     *
176
     * @param \DOMElement|null $parent The element we should append this endpoint to.
177
     * @return \DOMElement
178
     */
179
    public function toXML(?DOMElement $parent = null): DOMElement
180
    {
181
        $e = parent::instantiateParentElement($parent);
182
183
        foreach ($this->getAttributesNS() as $attr) {
184
            $attr->toXML($e);
185
        }
186
187
        $this->getAddress()->toXML($e);
188
189
        $this->getReferenceProperties()?->toXML($e);
190
        $this->getReferenceParameters()?->toXML($e);
191
        $this->getPortType()?->toXML($e);
192
        $this->getServiceName()?->toXML($e);
193
194
        foreach ($this->getElements() as $child) {
195
            if (!$child->isEmptyElement()) {
196
                $child->toXML($e);
197
            }
198
        }
199
200
        return $e;
201
    }
202
}
203