99
1010class ArrayToXml
1111{
12- protected $ document ;
12+ protected DOMDocument $ document ;
1313
14- protected $ replaceSpacesByUnderScoresInKeyNames = true ;
14+ protected bool $ replaceSpacesByUnderScoresInKeyNames = true ;
1515
16- protected $ addXmlDeclaration = true ;
16+ protected bool $ addXmlDeclaration = true ;
1717
18- protected $ numericTagNamePrefix = 'numeric_ ' ;
18+ protected string $ numericTagNamePrefix = 'numeric_ ' ;
1919
20- /**
21- * @param mixed[] $array
22- */
2320 public function __construct (
2421 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
3128 ) {
3229 $ this ->document = new DOMDocument ($ xmlVersion , $ xmlEncoding );
3330
@@ -57,9 +54,6 @@ public function setNumericTagNamePrefix(string $prefix): void
5754 $ this ->numericTagNamePrefix = $ prefix ;
5855 }
5956
60- /**
61- * @param mixed[] $array
62- */
6357 public static function convert (
6458 array $ array ,
6559 $ rootElement = '' ,
@@ -162,7 +156,7 @@ private function convertElement(DOMElement $element, $value): void
162156 $ element ->appendChild ($ fragment );
163157 } elseif ($ key === '__numeric ' ) {
164158 $ this ->addNumericNode ($ element , $ data );
165- } elseif (substr ($ key , 0 , 9 ) === '__custom: ' ) {
159+ } elseif (str_starts_with ($ key , '__custom: ' ) ) {
166160 $ this ->addNode ($ element , str_replace ('\: ' , ': ' , preg_split ('/(?<! \\\):/ ' , $ key )[1 ]), $ data );
167161 } else {
168162 $ this ->addNode ($ element , $ key , $ data );
@@ -206,7 +200,7 @@ protected function addCollectionNode(DOMElement $element, $value): void
206200 $ this ->convertElement ($ child , $ value );
207201 }
208202
209- protected function addSequentialNode (DOMElement $ element , $ value )
203+ protected function addSequentialNode (DOMElement $ element , $ value ): void
210204 {
211205 if (empty ($ element ->nodeValue ) && ! is_numeric ($ element ->nodeValue )) {
212206 $ element ->nodeValue = htmlspecialchars ($ value );
@@ -220,10 +214,9 @@ protected function addSequentialNode(DOMElement $element, $value)
220214 }
221215
222216 /**
223- * @param mixed[] $value
224217 * @return bool|mixed[]
225218 */
226- protected function isArrayAllKeySequential ($ value )
219+ protected function isArrayAllKeySequential (array | string $ value ): mixed
227220 {
228221 if (! is_array ($ value )) {
229222 return false ;
0 commit comments