9
9
10
10
class ArrayToXml
11
11
{
12
- protected $ document ;
12
+ protected DOMDocument $ document ;
13
13
14
- protected $ replaceSpacesByUnderScoresInKeyNames = true ;
14
+ protected bool $ replaceSpacesByUnderScoresInKeyNames = true ;
15
15
16
- protected $ addXmlDeclaration = true ;
16
+ protected bool $ addXmlDeclaration = true ;
17
17
18
- protected $ numericTagNamePrefix = 'numeric_ ' ;
18
+ protected string $ numericTagNamePrefix = 'numeric_ ' ;
19
19
20
- /**
21
- * @param mixed[] $array
22
- */
23
20
public function __construct (
24
21
array $ array ,
25
- $ rootElement = '' ,
26
- $ replaceSpacesByUnderScoresInKeyNames = true ,
27
- $ xmlEncoding = null ,
28
- $ xmlVersion = '1.0 ' ,
29
- $ domProperties = [],
30
- $ xmlStandalone = null
22
+ string | array $ rootElement = '' ,
23
+ bool $ replaceSpacesByUnderScoresInKeyNames = true ,
24
+ ? string $ xmlEncoding = null ,
25
+ string $ xmlVersion = '1.0 ' ,
26
+ array $ domProperties = [],
27
+ ? bool $ xmlStandalone = null
31
28
) {
32
29
$ this ->document = new DOMDocument ($ xmlVersion , $ xmlEncoding );
33
30
@@ -57,9 +54,6 @@ public function setNumericTagNamePrefix(string $prefix): void
57
54
$ this ->numericTagNamePrefix = $ prefix ;
58
55
}
59
56
60
- /**
61
- * @param mixed[] $array
62
- */
63
57
public static function convert (
64
58
array $ array ,
65
59
$ rootElement = '' ,
@@ -162,7 +156,7 @@ private function convertElement(DOMElement $element, $value): void
162
156
$ element ->appendChild ($ fragment );
163
157
} elseif ($ key === '__numeric ' ) {
164
158
$ this ->addNumericNode ($ element , $ data );
165
- } elseif (substr ($ key , 0 , 9 ) === '__custom: ' ) {
159
+ } elseif (str_starts_with ($ key , '__custom: ' ) ) {
166
160
$ this ->addNode ($ element , str_replace ('\: ' , ': ' , preg_split ('/(?<! \\\):/ ' , $ key )[1 ]), $ data );
167
161
} else {
168
162
$ this ->addNode ($ element , $ key , $ data );
@@ -206,7 +200,7 @@ protected function addCollectionNode(DOMElement $element, $value): void
206
200
$ this ->convertElement ($ child , $ value );
207
201
}
208
202
209
- protected function addSequentialNode (DOMElement $ element , $ value )
203
+ protected function addSequentialNode (DOMElement $ element , $ value ): void
210
204
{
211
205
if (empty ($ element ->nodeValue ) && ! is_numeric ($ element ->nodeValue )) {
212
206
$ element ->nodeValue = htmlspecialchars ($ value );
@@ -220,10 +214,9 @@ protected function addSequentialNode(DOMElement $element, $value)
220
214
}
221
215
222
216
/**
223
- * @param mixed[] $value
224
217
* @return bool|mixed[]
225
218
*/
226
- protected function isArrayAllKeySequential ($ value )
219
+ protected function isArrayAllKeySequential (array | string $ value ): mixed
227
220
{
228
221
if (! is_array ($ value )) {
229
222
return false ;
0 commit comments