You don't need this `else` and the whole nesting/indentation below since the above `if` does a return.
Additionally, it is safe to use `foreach()` on an empty array, so the `if` on line 439 could alse be removed.