The expression `$nodeArray` of type `array|null` is not guaranteed to be traversable. How about adding an additional type check?