77use DOMNode ;
88use Soap \Encoding \Xml \Node \Element ;
99use Soap \Encoding \Xml \Node \ElementList ;
10+ use VeeWee \Xml \Xmlns \Xmlns ;
1011use function VeeWee \Xml \Dom \Predicate \is_element ;
1112
1213/**
13- * @psalm-type LookupArray = array<string, string|Element|ElementList>
14+ * @psalm-type LookupArrayValue = string|Element|ElementList
15+ * @psalm-type LookupArray = array<string, LookupArrayValue>
1416 */
1517final class DocumentToLookupArrayReader
1618{
@@ -20,7 +22,7 @@ final class DocumentToLookupArrayReader
2022 public function __invoke (Element $ xml ): array
2123 {
2224 $ root = $ xml ->element ();
23- /** @var array<string, string|Element|ElementList> $nodes */
25+ /** @var LookupArray $nodes */
2426 $ nodes = [];
2527
2628 // Read all child elements.
@@ -38,7 +40,7 @@ public function __invoke(Element $xml): array
3840 $ currentElement = Element::fromDOMElement ($ element );
3941
4042 // Incrementally build up lists.
41- /** @var string|Element|ElementList $value */
43+ /** @var LookupArrayValue $value */
4244 $ value = match (true ) {
4345 $ previousValue instanceof ElementList => $ previousValue ->append ($ currentElement ),
4446 $ previousValue instanceof Element => new ElementList ($ previousValue , $ currentElement ),
@@ -50,8 +52,8 @@ public function __invoke(Element $xml): array
5052
5153 // It might be possible that the child is a regular textNode.
5254 // In that case, we use '_' as the key and the value of the textNode as value.
53- if (!$ nodes && $ content = trim ( $ root ->textContent ) ) {
54- $ nodes ['_ ' ] = $ content ;
55+ if (!$ nodes && $ root ->getAttributeNS (Xmlns:: xsi ()-> value (), ' nil ' ) !== ' true ' ) {
56+ $ nodes ['_ ' ] = $ root -> textContent ;
5557 }
5658
5759 // All attributes also need to be added as key => value pairs.
0 commit comments