I would reduce the indentation levels by using early returns:

```php
if (!$node->hasChildNodes()) {
     return $node->nodeValue;
}

if (1 === $node->childNodes->length && XML_TEXT_NODE === $node->firstChild->nodeType) {
    return $node->firstChild->nodeValue;
}

$value = array();
// ...

return $value;
```