@@ -24,7 +24,7 @@ public function getContentType(): string
2424 }
2525
2626 /**
27- * @return array<string, null|array|bool|float|int|string >
27+ * @return array<string, mixed >
2828 *
2929 * @throws RuntimeException
3030 */
@@ -36,10 +36,27 @@ public function decode(string $data): array
3636 throw RuntimeException::createNotParsable ($ this ->getContentType ());
3737 }
3838
39- return $ this ->decodeNode ($ document ->documentElement );
39+ $ documentElement = $ document ->documentElement ;
40+
41+ if (null === $ documentElement ) {
42+ throw RuntimeException::createNotParsable ($ this ->getContentType ());
43+ }
44+
45+ $ result = $ this ->decodeNode ($ documentElement );
46+
47+ if (!\is_array ($ result )) {
48+ throw RuntimeException::createNotParsable ($ this ->getContentType ());
49+ }
50+
51+ /** @var array<string, mixed> $result */
52+
53+ return $ result ;
4054 }
4155
42- private function decodeNode (\DOMNode $ node ): array |bool |float |int |string |null
56+ /**
57+ * @return null|array<mixed>|bool|float|int|string
58+ */
59+ private function decodeNode (\DOMElement $ node ): array |bool |float |int |string |null
4360 {
4461 $ nodeName = $ node ->nodeName ;
4562
@@ -73,13 +90,13 @@ private function decodeNode(\DOMNode $node): array|bool|float|int|string|null
7390 }
7491
7592 /**
76- * @return array<string, null|array|bool|float|int|string >
93+ * @return array<string, mixed >
7794 */
78- private function decodeObjectNode (\DOMNode $ node ): array
95+ private function decodeObjectNode (\DOMElement $ node ): array
7996 {
8097 $ data = [];
8198 foreach ($ node ->childNodes as $ childNode ) {
82- if ($ childNode instanceof \DOMText ) {
99+ if (! $ childNode instanceof \DOMElement ) {
83100 continue ;
84101 }
85102
@@ -90,13 +107,13 @@ private function decodeObjectNode(\DOMNode $node): array
90107 }
91108
92109 /**
93- * @return array<int, null|array|bool|float|int|string >
110+ * @return array<int, mixed >
94111 */
95- private function decodeArrayNode (\DOMNode $ node ): array
112+ private function decodeArrayNode (\DOMElement $ node ): array
96113 {
97114 $ data = [];
98115 foreach ($ node ->childNodes as $ childNode ) {
99- if ($ childNode instanceof \DOMText ) {
116+ if (! $ childNode instanceof \DOMElement ) {
100117 continue ;
101118 }
102119
@@ -106,19 +123,19 @@ private function decodeArrayNode(\DOMNode $node): array
106123 return $ data ;
107124 }
108125
109- private function decodeBooleanNode (\DOMNode $ node ): bool
126+ private function decodeBooleanNode (\DOMElement $ node ): bool
110127 {
111128 return 'true ' === $ node ->nodeValue ;
112129 }
113130
114- private function decodeStringNode (\DOMNode $ node ): string
131+ private function decodeStringNode (\DOMElement $ node ): string
115132 {
116- return $ node ->nodeValue ;
133+ return $ node ->nodeValue ?? '' ;
117134 }
118135
119- private function decodeNumberNode (\DOMNode $ node ): float |int
136+ private function decodeNumberNode (\DOMElement $ node ): float |int
120137 {
121- $ value = $ node ->nodeValue ;
138+ $ value = $ node ->nodeValue ?? ' 0 ' ;
122139
123140 if ($ value === (string ) (int ) $ value ) {
124141 return (int ) $ value ;
0 commit comments