Skip to content

Commit 1ff4535

Browse files
committed
Revert unjust const>enum convertion & fix any other codesniffer issues
1 parent 3c65906 commit 1ff4535

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+338
-278
lines changed

src/XML/Assert/Assert.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
/**
1010
* @package simplesamlphp/xml-common
1111
*
12-
* @method static void validAllowedXPathFilter(mixed $value, array $allowed_axes, array $allowed_functions, string $message = '', string $exception = '')
12+
* @phpcs:ignore Generic.Files.LineLength.TooLong
13+
* @method static void validAllowedXPathFilter(mixed $value, string[] $allowed_axes, string[] $allowed_functions, string $message = '', string $exception = '')
1314
* @method static void validAnyURI(mixed $value, string $message = '', string $exception = '')
1415
* @method static void validBase64Binary(mixed $value, string $message = '', string $exception = '')
1516
* @method static void validBoolean(mixed $value, string $message = '', string $exception = '')
@@ -52,7 +53,8 @@
5253
* @method static void validUnsignedShort(mixed $value, string $message = '', string $exception = '')
5354
* @method static void validYear(mixed $value, string $message = '', string $exception = '')
5455
* @method static void validYearMonth(mixed $value, string $message = '', string $exception = '')
55-
* @method static void nullOrValidAllowedXPathFilter(mixed $value, array $allowed_axes, array $allowed_functions, string $message = '', string $exception = '')
56+
* @phpcs:ignore Generic.Files.LineLength.TooLong
57+
* @method static void nullOrValidAllowedXPathFilter(mixed $value, string[] $allowed_axes, string[] $allowed_functions, string $message = '', string $exception = '')
5658
* @method static void nullOrValidAnyURI(mixed $value, string $message = '', string $exception = '')
5759
* @method static void nullOrValidBase64Binary(mixed $value, string $message = '', string $exception = '')
5860
* @method static void nullOrValidBoolean(mixed $value, string $message = '', string $exception = '')
@@ -95,7 +97,8 @@
9597
* @method static void nullOrValidUnsignedShort(mixed $value, string $message = '', string $exception = '')
9698
* @method static void nullOrValidYear(mixed $value, string $message = '', string $exception = '')
9799
* @method static void nullOrValidYearMonth(mixed $value, string $message = '', string $exception = '')
98-
* @method static void allValidAllowedXPathFilter(mixed $value, array $allowed_axes, array $allowed_functions, string $message = '', string $exception = '')
100+
* @phpcs:ignore Generic.Files.LineLength.TooLong
101+
* @method static void allValidAllowedXPathFilter(mixed $value, string[] $allowed_axes, string[] $allowed_functions, string $message = '', string $exception = '')
99102
* @method static void allValidAnyURI(mixed $value, string $message = '', string $exception = '')
100103
* @method static void allValidBase64Binary(mixed $value, string $message = '', string $exception = '')
101104
* @method static void allValidBoolean(mixed $value, string $message = '', string $exception = '')

src/XML/ExtendableAttributesTrait.php

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use SimpleSAML\XML\Attribute;
1111
use SimpleSAML\XML\Constants as C;
1212
use SimpleSAML\XMLSchema\Type\StringValue;
13-
use SimpleSAML\XMLSchema\XML\Enumeration\NamespaceEnum;
13+
use SimpleSAML\XMLSchema\XML\Constants\NS;
1414

1515
use function array_diff;
1616
use function array_map;
@@ -90,17 +90,12 @@ public function getAttributesNS(): array
9090
* NOTE: In case the namespace is ##any, this method will also return local non-namespaced attributes!
9191
*
9292
* @param \DOMElement $xml
93-
* @param (
94-
* \SimpleSAML\XMLSchema\XML\Enumeration\NamespaceEnum|
95-
* array<\SimpleSAML\XMLSchema\XML\Enumeration\NamespaceEnum|string>|
96-
* null
97-
* ) $namespace
98-
*
99-
* @return array<int, \SimpleSAML\XML\Attribute> $attributes
93+
* @param string|string[]|null $namespace
94+
* @return array<int, \SimpleSAML\XML\Attribute>
10095
*/
10196
protected static function getAttributesNSFromXML(
10297
DOMElement $xml,
103-
NamespaceEnum|array|null $namespace = null,
98+
string|array|null $namespace = null,
10499
): array {
105100
$namespace = $namespace ?? self::XS_ANY_ATTR_NAMESPACE;
106101
$exclusionList = self::getAttributeExclusions();
@@ -109,16 +104,16 @@ protected static function getAttributesNSFromXML(
109104
// Validate namespace value
110105
if (!is_array($namespace)) {
111106
// Must be one of the predefined values
112-
Assert::oneOf($namespace, NamespaceEnum::cases());
107+
Assert::oneOf($namespace, NS::$PREDEFINED);
113108

114109
foreach ($xml->attributes as $a) {
115110
if (in_array([$a->namespaceURI, $a->localName], $exclusionList, true)) {
116111
continue;
117-
} elseif ($namespace === NamespaceEnum::Other && in_array($a->namespaceURI, [self::NS, null], true)) {
112+
} elseif ($namespace === NS::OTHER && in_array($a->namespaceURI, [self::NS, null], true)) {
118113
continue;
119-
} elseif ($namespace === NamespaceEnum::TargetNamespace && $a->namespaceURI !== self::NS) {
114+
} elseif ($namespace === NS::TARGETNAMESPACE && $a->namespaceURI !== self::NS) {
120115
continue;
121-
} elseif ($namespace === NamespaceEnum::Local && $a->namespaceURI !== null) {
116+
} elseif ($namespace === NS::LOCAL && $a->namespaceURI !== null) {
122117
continue;
123118
}
124119

@@ -133,16 +128,16 @@ protected static function getAttributesNSFromXML(
133128
// Array must be non-empty and cannot contain ##any or ##other
134129
Assert::notEmpty($namespace);
135130
Assert::allStringNotEmpty($namespace);
136-
Assert::allNotSame($namespace, NamespaceEnum::Any);
137-
Assert::allNotSame($namespace, NamespaceEnum::Other);
131+
Assert::allNotSame($namespace, NS::ANY);
132+
Assert::allNotSame($namespace, NS::OTHER);
138133

139134
// Replace the ##targetedNamespace with the actual namespace
140-
if (($key = array_search(NamespaceEnum::TargetNamespace, $namespace)) !== false) {
135+
if (($key = array_search(NS::TARGETNAMESPACE, $namespace)) !== false) {
141136
$namespace[$key] = self::NS;
142137
}
143138

144139
// Replace the ##local with null
145-
if (($key = array_search(NamespaceEnum::Local, $namespace)) !== false) {
140+
if (($key = array_search(NS::LOCAL, $namespace)) !== false) {
146141
$namespace[$key] = null;
147142
}
148143

@@ -183,12 +178,12 @@ protected function setAttributesNS(array $attributes): void
183178
// Validate namespace value
184179
if (!is_array($namespace)) {
185180
// Must be one of the predefined values
186-
Assert::oneOf($namespace, NamespaceEnum::cases());
181+
Assert::oneOf($namespace, NS::$PREDEFINED);
187182
} else {
188183
// Array must be non-empty and cannot contain ##any or ##other
189184
Assert::notEmpty($namespace);
190-
Assert::allNotSame($namespace, NamespaceEnum::Any);
191-
Assert::allNotSame($namespace, NamespaceEnum::Other);
185+
Assert::allNotSame($namespace, NS::ANY);
186+
Assert::allNotSame($namespace, NS::OTHER);
192187
}
193188

194189
// Get namespaces for all attributes
@@ -203,20 +198,20 @@ function (Attribute $attr) {
203198
$attributes,
204199
);
205200

206-
if ($namespace === NamespaceEnum::Local) {
201+
if ($namespace === NS::LOCAL) {
207202
// If ##local then all namespaces must be null
208203
Assert::allNull($actual_namespaces);
209204
} elseif (is_array($namespace)) {
210205
// Make a local copy of the property that we can edit
211206
$allowed_namespaces = $namespace;
212207

213208
// Replace the ##targetedNamespace with the actual namespace
214-
if (($key = array_search(NamespaceEnum::TargetNamespace, $allowed_namespaces)) !== false) {
209+
if (($key = array_search(NS::TARGETNAMESPACE, $allowed_namespaces)) !== false) {
215210
$allowed_namespaces[$key] = self::NS;
216211
}
217212

218213
// Replace the ##local with null
219-
if (($key = array_search(NamespaceEnum::Local, $allowed_namespaces)) !== false) {
214+
if (($key = array_search(NS::LOCAL, $allowed_namespaces)) !== false) {
220215
$allowed_namespaces[$key] = null;
221216
}
222217

@@ -230,13 +225,13 @@ function (Attribute $attr) {
230225
),
231226
);
232227
} else {
233-
if ($namespace === NamespaceEnum::Other) {
228+
if ($namespace === NS::OTHER) {
234229
// All attributes must be namespaced, ergo non-null
235230
Assert::allNotNull($actual_namespaces);
236231

237232
// Must be any namespace other than the parent element
238233
Assert::allNotSame($actual_namespaces, self::NS);
239-
} elseif ($namespace === NamespaceEnum::TargetNamespace) {
234+
} elseif ($namespace === NS::TARGETNAMESPACE) {
240235
// Must be the same namespace as the one of the parent element
241236
Assert::allSame($actual_namespaces, self::NS);
242237
}
@@ -254,12 +249,9 @@ function (Attribute $attr) {
254249

255250

256251
/**
257-
* @return (
258-
* array<\SimpleSAML\XMLSchema\XML\Enumeration\NamespaceEnum|string>|
259-
* \SimpleSAML\XMLSchema\XML\Enumeration\NamespaceEnum
260-
* )[]
252+
* @return string[]|string
261253
*/
262-
public function getAttributeNamespace(): array|NamespaceEnum
254+
public function getAttributeNamespace(): array|string
263255
{
264256
Assert::true(
265257
defined('self::XS_ANY_ATTR_NAMESPACE'),

src/XML/ExtendableElementTrait.php

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use SimpleSAML\XML\Chunk;
1111
use SimpleSAML\XML\Constants as C;
1212
use SimpleSAML\XML\Registry\ElementRegistry;
13-
use SimpleSAML\XMLSchema\XML\Enumeration\NamespaceEnum;
13+
use SimpleSAML\XMLSchema\XML\Constants\NS;
1414

1515
use function array_diff;
1616
use function array_map;
@@ -38,17 +38,12 @@ trait ExtendableElementTrait
3838
* NOTE: In case the namespace is ##any, this method will also return local non-namespaced elements!
3939
*
4040
* @param \DOMElement $xml
41-
* @param (
42-
* \SimpleSAML\XMLSchema\XML\Enumeration\NamespaceEnum|
43-
* array<\SimpleSAML\XMLSchema\XML\Enumeration\NamespaceEnum|string>|
44-
* null
45-
* ) $namespace
46-
*
41+
* @param string|string[]|null $namespace
4742
* @return list<\SimpleSAML\XML\SerializableElementInterface> $elements
4843
*/
4944
protected static function getChildElementsFromXML(
5045
DOMElement $xml,
51-
NamespaceEnum|array|null $namespace = null,
46+
string|array|null $namespace = null,
5247
): array {
5348
$namespace = $namespace ?? self::XS_ANY_ELT_NAMESPACE;
5449
$exclusionList = self::getElementExclusions();
@@ -58,18 +53,18 @@ protected static function getChildElementsFromXML(
5853
// Validate namespace value
5954
if (!is_array($namespace)) {
6055
// Must be one of the predefined values
61-
Assert::oneOf($namespace, NamespaceEnum::cases());
56+
Assert::oneOf($namespace, NS::$PREDEFINED);
6257

6358
foreach ($xml->childNodes as $elt) {
6459
if (!($elt instanceof DOMElement)) {
6560
continue;
6661
} elseif (in_array([$elt->namespaceURI, $elt->localName], $exclusionList, true)) {
6762
continue;
68-
} elseif ($namespace === NamespaceEnum::Other && in_array($elt->namespaceURI, [self::NS, null], true)) {
63+
} elseif ($namespace === NS::OTHER && in_array($elt->namespaceURI, [self::NS, null], true)) {
6964
continue;
70-
} elseif ($namespace === NamespaceEnum::TargetNamespace && $elt->namespaceURI !== self::NS) {
65+
} elseif ($namespace === NS::TARGETNAMESPACE && $elt->namespaceURI !== self::NS) {
7166
continue;
72-
} elseif ($namespace === NamespaceEnum::Local && $elt->namespaceURI !== null) {
67+
} elseif ($namespace === NS::LOCAL && $elt->namespaceURI !== null) {
7368
continue;
7469
}
7570

@@ -80,16 +75,16 @@ protected static function getChildElementsFromXML(
8075
// Array must be non-empty and cannot contain ##any or ##other
8176
Assert::notEmpty($namespace);
8277
Assert::allStringNotEmpty($namespace);
83-
Assert::allNotSame($namespace, NamespaceEnum::Any);
84-
Assert::allNotSame($namespace, NamespaceEnum::Other);
78+
Assert::allNotSame($namespace, NS::ANY);
79+
Assert::allNotSame($namespace, NS::OTHER);
8580

8681
// Replace the ##targetedNamespace with the actual namespace
87-
if (($key = array_search(NamespaceEnum::TargetNamespace, $namespace)) !== false) {
82+
if (($key = array_search(NS::TARGETNAMESPACE, $namespace)) !== false) {
8883
$namespace[$key] = self::NS;
8984
}
9085

9186
// Replace the ##local with null
92-
if (($key = array_search(NamespaceEnum::Local, $namespace)) !== false) {
87+
if (($key = array_search(NS::LOCAL, $namespace)) !== false) {
9388
$namespace[$key] = null;
9489
}
9590

@@ -126,12 +121,12 @@ protected function setElements(array $elements): void
126121
// Validate namespace value
127122
if (!is_array($namespace)) {
128123
// Must be one of the predefined values
129-
Assert::oneOf($namespace, NamespaceEnum::cases());
124+
Assert::oneOf($namespace, NS::$PREDEFINED);
130125
} else {
131126
// Array must be non-empty and cannot contain ##any or ##other
132127
Assert::notEmpty($namespace);
133-
Assert::allNotSame($namespace, NamespaceEnum::Any);
134-
Assert::allNotSame($namespace, NamespaceEnum::Other);
128+
Assert::allNotSame($namespace, NS::ANY);
129+
Assert::allNotSame($namespace, NS::OTHER);
135130
}
136131

137132
// Get namespaces for all elements
@@ -146,20 +141,20 @@ function (AbstractElement|Chunk $elt): ?string {
146141
$elements,
147142
);
148143

149-
if ($namespace === NamespaceEnum::Local) {
144+
if ($namespace === NS::LOCAL) {
150145
// If ##local then all namespaces must be null
151146
Assert::allNull($actual_namespaces);
152147
} elseif (is_array($namespace)) {
153148
// Make a local copy of the property that we can edit
154149
$allowed_namespaces = $namespace;
155150

156151
// Replace the ##targetedNamespace with the actual namespace
157-
if (($key = array_search(NamespaceEnum::TargetNamespace, $allowed_namespaces)) !== false) {
152+
if (($key = array_search(NS::TARGETNAMESPACE, $allowed_namespaces)) !== false) {
158153
$allowed_namespaces[$key] = self::NS;
159154
}
160155

161156
// Replace the ##local with null
162-
if (($key = array_search(NamespaceEnum::Local, $allowed_namespaces)) !== false) {
157+
if (($key = array_search(NS::LOCAL, $allowed_namespaces)) !== false) {
163158
$allowed_namespaces[$key] = null;
164159
}
165160

@@ -172,11 +167,11 @@ function (AbstractElement|Chunk $elt): ?string {
172167
self::NS,
173168
),
174169
);
175-
} elseif ($namespace === NamespaceEnum::Other) {
170+
} elseif ($namespace === NS::OTHER) {
176171
// Must be any namespace other than the parent element, excluding elements with no namespace
177172
Assert::notInArray(null, $actual_namespaces);
178173
Assert::allNotSame($actual_namespaces, self::NS);
179-
} elseif ($namespace === NamespaceEnum::TargetNamespace) {
174+
} elseif ($namespace === NS::TARGETNAMESPACE) {
180175
// Must be the same namespace as the one of the parent element
181176
Assert::allSame($actual_namespaces, self::NS);
182177
} else {
@@ -206,12 +201,9 @@ public function getElements(): array
206201

207202

208203
/**
209-
* @return (
210-
* array<\SimpleSAML\XMLSchema\XML\Enumeration\NamespaceEnum|string>|
211-
* \SimpleSAML\XMLSchema\XML\Enumeration\NamespaceEnum
212-
* )
204+
* @return string|string[]
213205
*/
214-
public function getElementNamespace(): array|NamespaceEnum
206+
public function getElementNamespace(): array|string
215207
{
216208
Assert::true(
217209
defined('self::XS_ANY_ELT_NAMESPACE'),

src/XML/TestUtils/ArrayizableElementTestTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* Test for arrayizable XML classes to perform default serialization tests.
1313
*
1414
* @package simplesamlphp\xml-common
15+
* @phpstan-ignore trait.unused
1516
*/
1617
trait ArrayizableElementTestTrait
1718
{

src/XML/TestUtils/SchemaValidationTestTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Test for AbstractElement classes to perform schema validation tests.
1414
*
1515
* @package simplesamlphp\xml-common
16+
* @phpstan-ignore trait.unused
1617
*/
1718
trait SchemaValidationTestTrait
1819
{

src/XML/TestUtils/SerializableElementTestTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Test for Serializable XML classes to perform default serialization tests.
1414
*
1515
* @package simplesamlphp\xml-common
16+
* @phpstan-ignore trait.unused
1617
*/
1718
trait SerializableElementTestTrait
1819
{

src/XML/TypedTextContentTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* Trait for elements that hold a typed textContent value.
2020
*
2121
* @package simplesaml/xml-common
22+
* @phpstan-ignore trait.unused
2223
*/
2324
trait TypedTextContentTrait
2425
{

src/XML/XML/Trait/SpecialAttrsTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Trait grouping common functionality for elements that use the specialAttrs-attributeGroup.
1414
*
1515
* @package simplesamlphp/xml-common
16+
* @phpstan-ignore trait.unused
1617
*/
1718
trait SpecialAttrsTrait
1819
{

src/XMLSchema/Type/Interface/AbstractAnySimpleType.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public function getRawValue(): string
6464
* Sanitize the value.
6565
*
6666
* @param string $value The value
67-
* @throws \Exception on failure
6867
* @return string
6968
*/
7069
protected function sanitizeValue(string $value): string
@@ -81,7 +80,6 @@ protected function sanitizeValue(string $value): string
8180
* Validate the value.
8281
*
8382
* @param string $value The value
84-
* @throws \Exception on failure
8583
* @return void
8684
*/
8785
protected function validateValue(/** @scrutinizer-ignore */string $value): void

0 commit comments

Comments
 (0)