Skip to content

Commit 0938d34

Browse files
committed
Bugfix: use self instead of static
1 parent 66e3dd2 commit 0938d34

File tree

5 files changed

+35
-105
lines changed

5 files changed

+35
-105
lines changed

src/ExtendableAttributesTrait.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ public function getAttributesNS(): array
9595
*/
9696
protected static function getAttributesNSFromXML(DOMElement $xml, NS|array $namespace = null): array
9797
{
98-
$namespace = $namespace ?? static::XS_ANY_ATTR_NAMESPACE;
99-
$exclusionList = static::getAttributeExclusions();
98+
$namespace = $namespace ?? self::XS_ANY_ATTR_NAMESPACE;
99+
$exclusionList = self::getAttributeExclusions();
100100
$attributes = [];
101101

102102
// Validate namespace value
@@ -107,9 +107,9 @@ protected static function getAttributesNSFromXML(DOMElement $xml, NS|array $name
107107
foreach ($xml->attributes as $a) {
108108
if (in_array([$a->namespaceURI, $a->localName], $exclusionList, true)) {
109109
continue;
110-
} elseif ($namespace === NS::OTHER && in_array($a->namespaceURI, [static::NS, null], true)) {
110+
} elseif ($namespace === NS::OTHER && in_array($a->namespaceURI, [self::NS, null], true)) {
111111
continue;
112-
} elseif ($namespace === NS::TARGET && $a->namespaceURI !== static::NS) {
112+
} elseif ($namespace === NS::TARGET && $a->namespaceURI !== self::NS) {
113113
continue;
114114
} elseif ($namespace === NS::LOCAL && $a->namespaceURI !== null) {
115115
continue;
@@ -126,7 +126,7 @@ protected static function getAttributesNSFromXML(DOMElement $xml, NS|array $name
126126

127127
// Replace the ##targetedNamespace with the actual namespace
128128
if (($key = array_search(NS::TARGET, $namespace)) !== false) {
129-
$namespace[$key] = static::NS;
129+
$namespace[$key] = self::NS;
130130
}
131131

132132
// Replace the ##local with null
@@ -195,7 +195,7 @@ function (Attribute $attr) {
195195

196196
// Replace the ##targetedNamespace with the actual namespace
197197
if (($key = array_search(NS::TARGET, $allowed_namespaces)) !== false) {
198-
$allowed_namespaces[$key] = static::NS;
198+
$allowed_namespaces[$key] = self::NS;
199199
}
200200

201201
// Replace the ##local with null
@@ -209,7 +209,7 @@ function (Attribute $attr) {
209209
sprintf(
210210
'Attributes from namespaces [ %s ] are not allowed inside a %s element.',
211211
rtrim(implode(', ', $diff)),
212-
static::NS,
212+
self::NS,
213213
),
214214
);
215215
} else {
@@ -218,14 +218,14 @@ function (Attribute $attr) {
218218
Assert::allNotNull($actual_namespaces);
219219

220220
// Must be any namespace other than the parent element
221-
Assert::allNotSame($actual_namespaces, static::NS);
221+
Assert::allNotSame($actual_namespaces, self::NS);
222222
} elseif ($namespace === NS::TARGET) {
223223
// Must be the same namespace as the one of the parent element
224-
Assert::allSame($actual_namespaces, static::NS);
224+
Assert::allSame($actual_namespaces, self::NS);
225225
}
226226
}
227227

228-
$exclusionList = static::getAttributeExclusions();
228+
$exclusionList = self::getAttributeExclusions();
229229
foreach ($attributes as $i => $attr) {
230230
if (in_array([$attr->getNamespaceURI(), $attr->getAttrName()], $exclusionList, true)) {
231231
unset($attributes[$i]);
@@ -243,13 +243,13 @@ function (Attribute $attr) {
243243
public function getAttributeNamespace(): array|NS
244244
{
245245
Assert::true(
246-
defined('static::XS_ANY_ATTR_NAMESPACE'),
247-
self::getClassName(static::class)
246+
defined('self::XS_ANY_ATTR_NAMESPACE'),
247+
self::getClassName(self::class)
248248
. '::XS_ANY_ATTR_NAMESPACE constant must be defined and set to the namespace for the xs:anyAttribute.',
249249
RuntimeException::class,
250250
);
251251

252-
return static::XS_ANY_ATTR_NAMESPACE;
252+
return self::XS_ANY_ATTR_NAMESPACE;
253253
}
254254

255255

@@ -260,8 +260,8 @@ public function getAttributeNamespace(): array|NS
260260
*/
261261
public static function getAttributeExclusions(): array
262262
{
263-
if (defined('static::XS_ANY_ATTR_EXCLUSIONS')) {
264-
return static::XS_ANY_ATTR_EXCLUSIONS;
263+
if (defined('self::XS_ANY_ATTR_EXCLUSIONS')) {
264+
return self::XS_ANY_ATTR_EXCLUSIONS;
265265
}
266266

267267
return [];

src/ExtendableElementTrait.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ trait ExtendableElementTrait
4444
*/
4545
protected static function getChildElementsFromXML(DOMElement $xml, NS|array $namespace = null): array
4646
{
47-
$namespace = $namespace ?? static::XS_ANY_ELT_NAMESPACE;
48-
$exclusionList = static::getElementExclusions();
47+
$namespace = $namespace ?? self::XS_ANY_ELT_NAMESPACE;
48+
$exclusionList = self::getElementExclusions();
4949
$registry = ElementRegistry::getInstance();
5050
$elements = [];
5151

@@ -59,9 +59,9 @@ protected static function getChildElementsFromXML(DOMElement $xml, NS|array $nam
5959
continue;
6060
} elseif (in_array([$elt->namespaceURI, $elt->localName], $exclusionList, true)) {
6161
continue;
62-
} elseif ($namespace === NS::OTHER && in_array($elt->namespaceURI, [static::NS, null], true)) {
62+
} elseif ($namespace === NS::OTHER && in_array($elt->namespaceURI, [self::NS, null], true)) {
6363
continue;
64-
} elseif ($namespace === NS::TARGET && $elt->namespaceURI !== static::NS) {
64+
} elseif ($namespace === NS::TARGET && $elt->namespaceURI !== self::NS) {
6565
continue;
6666
} elseif ($namespace === NS::LOCAL && $elt->namespaceURI !== null) {
6767
continue;
@@ -79,7 +79,7 @@ protected static function getChildElementsFromXML(DOMElement $xml, NS|array $nam
7979

8080
// Replace the ##targetedNamespace with the actual namespace
8181
if (($key = array_search(NS::TARGET, $namespace)) !== false) {
82-
$namespace[$key] = static::NS;
82+
$namespace[$key] = self::NS;
8383
}
8484

8585
// Replace the ##local with null
@@ -149,7 +149,7 @@ function (SerializableElementInterface $elt) {
149149

150150
// Replace the ##targetedNamespace with the actual namespace
151151
if (($key = array_search(NS::TARGET, $allowed_namespaces)) !== false) {
152-
$allowed_namespaces[$key] = static::NS;
152+
$allowed_namespaces[$key] = self::NS;
153153
}
154154

155155
// Replace the ##local with null
@@ -163,21 +163,21 @@ function (SerializableElementInterface $elt) {
163163
sprintf(
164164
'Elements from namespaces [ %s ] are not allowed inside a %s element.',
165165
rtrim(implode(', ', $diff)),
166-
static::NS,
166+
self::NS,
167167
),
168168
);
169169
} elseif ($namespace === NS::OTHER) {
170170
// Must be any namespace other than the parent element, excluding elements with no namespace
171171
Assert::notInArray(null, $actual_namespaces);
172-
Assert::allNotSame($actual_namespaces, static::NS);
172+
Assert::allNotSame($actual_namespaces, self::NS);
173173
} elseif ($namespace === NS::TARGET) {
174174
// Must be the same namespace as the one of the parent element
175-
Assert::allSame($actual_namespaces, static::NS);
175+
Assert::allSame($actual_namespaces, self::NS);
176176
} else {
177177
// XS_ANY_NS_ANY
178178
}
179179

180-
$exclusionList = static::getElementExclusions();
180+
$exclusionList = self::getElementExclusions();
181181
foreach ($elements as $i => $elt) {
182182
if (in_array([$elt->getNamespaceURI(), $elt->getLocalName()], $exclusionList, true)) {
183183
unset($elements[$i]);
@@ -205,13 +205,13 @@ public function getElements(): array
205205
public function getElementNamespace(): array|NS
206206
{
207207
Assert::true(
208-
defined('static::XS_ANY_ELT_NAMESPACE'),
209-
self::getClassName(static::class)
208+
defined('self::XS_ANY_ELT_NAMESPACE'),
209+
self::getClassName(self::class)
210210
. '::XS_ANY_ELT_NAMESPACE constant must be defined and set to the namespace for the xs:any element.',
211211
RuntimeException::class,
212212
);
213213

214-
return static::XS_ANY_ELT_NAMESPACE;
214+
return self::XS_ANY_ELT_NAMESPACE;
215215
}
216216

217217

@@ -222,8 +222,8 @@ public function getElementNamespace(): array|NS
222222
*/
223223
public static function getElementExclusions(): array
224224
{
225-
if (defined('static::XS_ANY_ELT_EXCLUSIONS')) {
226-
return static::XS_ANY_ELT_EXCLUSIONS;
225+
if (defined('self::XS_ANY_ELT_EXCLUSIONS')) {
226+
return self::XS_ANY_ELT_EXCLUSIONS;
227227
}
228228

229229
return [];

tests/Utils/ExtendableAttributesElement.php

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class ExtendableAttributesElement extends AbstractElement
2020
{
2121
use ExtendableAttributesTrait;
2222

23-
2423
/** @var string */
2524
public const NS = 'urn:x-simplesamlphp:namespace';
2625

@@ -31,36 +30,14 @@ class ExtendableAttributesElement extends AbstractElement
3130
public const LOCALNAME = 'ExtendableAttributesElement';
3231

3332
/** @var string|\SimpleSAML\XML\XsNamespace */
34-
public const XS_ANY_ATTR_NAMESPACE = NS::ANY;
33+
final public const XS_ANY_ATTR_NAMESPACE = NS::ANY;
3534

3635
/** @var array{array{string, string}} */
37-
public const XS_ANY_ATTR_EXCLUSIONS = [
36+
final public const XS_ANY_ATTR_EXCLUSIONS = [
3837
['urn:x-simplesamlphp:namespace', 'attr3'],
3938
];
4039

4140

42-
/**
43-
* Get the namespace for the element.
44-
*
45-
* @return string
46-
*/
47-
public static function getNamespaceURI(): string
48-
{
49-
return static::NS;
50-
}
51-
52-
53-
/**
54-
* Get the namespace-prefix for the element.
55-
*
56-
* @return string
57-
*/
58-
public static function getNamespacePrefix(): string
59-
{
60-
return static::NS_PREFIX;
61-
}
62-
63-
6441
/**
6542
* Initialize element.
6643
*

tests/Utils/ExtendableElement.php

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use DOMElement;
88
use SimpleSAML\XML\AbstractElement;
9-
use SimpleSAML\XML\Chunk;
109
use SimpleSAML\XML\ExtendableElementTrait;
1110
use SimpleSAML\XML\SerializableElementTrait;
1211
use SimpleSAML\XML\XsNamespace as NS;
@@ -21,7 +20,6 @@ class ExtendableElement extends AbstractElement
2120
use ExtendableElementTrait;
2221
use SerializableElementTrait;
2322

24-
2523
/** @var string */
2624
public const NS = 'urn:x-simplesamlphp:namespace';
2725

@@ -32,36 +30,14 @@ class ExtendableElement extends AbstractElement
3230
public const LOCALNAME = 'ExtendableElement';
3331

3432
/** @var \SimpleSAML\XML\XsNamespace|array<int, \SimpleSAML\XML\XsNamespace> */
35-
public const XS_ANY_ELT_NAMESPACE = NS::ANY;
33+
final public const XS_ANY_ELT_NAMESPACE = NS::ANY;
3634

3735
/** @var array{array{string, string}} */
38-
public const XS_ANY_ELT_EXCLUSIONS = [
36+
final public const XS_ANY_ELT_EXCLUSIONS = [
3937
['urn:custom:other', 'Chunk'],
4038
];
4139

4240

43-
/**
44-
* Get the namespace for the element.
45-
*
46-
* @return string
47-
*/
48-
public static function getNamespaceURI(): string
49-
{
50-
return static::NS;
51-
}
52-
53-
54-
/**
55-
* Get the namespace-prefix for the element.
56-
*
57-
* @return string
58-
*/
59-
public static function getNamespacePrefix(): string
60-
{
61-
return static::NS_PREFIX;
62-
}
63-
64-
6541
/**
6642
* Initialize element.
6743
*
@@ -81,14 +57,7 @@ final public function __construct(array $elements)
8157
*/
8258
public static function fromXML(DOMElement $xml): static
8359
{
84-
$children = [];
85-
foreach ($xml->childNodes as $node) {
86-
if ($node instanceof DOMElement) {
87-
$children[] = Chunk::fromXML($node);
88-
}
89-
}
90-
91-
return new static($children);
60+
return new static(self::getChildElementsFromXML($xml));
9261
}
9362

9463

tests/XML/ExtendableAttributesTraitTest.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -222,22 +222,6 @@ public function getAttributeNamespace(): array|NS
222222
}
223223

224224

225-
/**
226-
*/
227-
public function testLocalNamespacePassingTargetThrowsAnException(): void
228-
{
229-
$this->expectException(AssertionFailedException::class);
230-
new class ([self::$target]) extends ExtendableAttributesElement {
231-
/** @return array<int, NS>|NS */
232-
public function getAtributeNamespace(): array|NS
233-
{
234-
return NS::LOCAL;
235-
}
236-
};
237-
}
238-
239-
240-
241225
/**
242226
*/
243227
public function testLocalNamespacePassingOtherThrowsAnException(): void

0 commit comments

Comments
 (0)