@@ -24,22 +24,37 @@ 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 */
3131 public function decode (string $ data ): array
3232 {
3333 $ document = new \DOMDocument ();
3434
35- if (!@$ document ->loadXML ($ data )) {
35+ @$ document ->loadXML ($ data );
36+
37+ $ documentElement = $ document ->documentElement ;
38+
39+ if (null === $ documentElement ) {
3640 throw RuntimeException::createNotParsable ($ this ->getContentType ());
3741 }
3842
39- return $ this ->decodeNode ($ document ->documentElement );
43+ $ result = $ this ->decodeNode ($ documentElement );
44+
45+ if (!\is_array ($ result )) {
46+ throw RuntimeException::createNotParsable ($ this ->getContentType ());
47+ }
48+
49+ /** @var array<string, mixed> $result */
50+
51+ return $ result ;
4052 }
4153
42- private function decodeNode (\DOMNode $ node ): array |bool |float |int |string |null
54+ /**
55+ * @return null|array<mixed>|bool|float|int|string
56+ */
57+ private function decodeNode (\DOMElement $ node ): array |bool |float |int |string |null
4358 {
4459 $ nodeName = $ node ->nodeName ;
4560
@@ -73,13 +88,13 @@ private function decodeNode(\DOMNode $node): array|bool|float|int|string|null
7388 }
7489
7590 /**
76- * @return array<string, null|array|bool|float|int|string >
91+ * @return array<string, mixed >
7792 */
78- private function decodeObjectNode (\DOMNode $ node ): array
93+ private function decodeObjectNode (\DOMElement $ node ): array
7994 {
8095 $ data = [];
8196 foreach ($ node ->childNodes as $ childNode ) {
82- if ($ childNode instanceof \DOMText ) {
97+ if (! $ childNode instanceof \DOMElement ) {
8398 continue ;
8499 }
85100
@@ -90,13 +105,13 @@ private function decodeObjectNode(\DOMNode $node): array
90105 }
91106
92107 /**
93- * @return array<int, null|array|bool|float|int|string >
108+ * @return array<int, mixed >
94109 */
95- private function decodeArrayNode (\DOMNode $ node ): array
110+ private function decodeArrayNode (\DOMElement $ node ): array
96111 {
97112 $ data = [];
98113 foreach ($ node ->childNodes as $ childNode ) {
99- if ($ childNode instanceof \DOMText ) {
114+ if (! $ childNode instanceof \DOMElement ) {
100115 continue ;
101116 }
102117
@@ -106,19 +121,19 @@ private function decodeArrayNode(\DOMNode $node): array
106121 return $ data ;
107122 }
108123
109- private function decodeBooleanNode (\DOMNode $ node ): bool
124+ private function decodeBooleanNode (\DOMElement $ node ): bool
110125 {
111126 return 'true ' === $ node ->nodeValue ;
112127 }
113128
114- private function decodeStringNode (\DOMNode $ node ): string
129+ private function decodeStringNode (\DOMElement $ node ): string
115130 {
116- return $ node ->nodeValue ;
131+ return $ node ->nodeValue ?? '' ;
117132 }
118133
119- private function decodeNumberNode (\DOMNode $ node ): float |int
134+ private function decodeNumberNode (\DOMElement $ node ): float |int
120135 {
121- $ value = $ node ->nodeValue ;
136+ $ value = $ node ->nodeValue ?? ' 0 ' ;
122137
123138 if ($ value === (string ) (int ) $ value ) {
124139 return (int ) $ value ;
0 commit comments