We can optimize this into an array_map and also implement the "is_scalar" into processParameterValue method easily, heavily simplifying the code.
Also, is_scalar there would also improve performance by reducing the amount of checks for each parameter when executing a query.