Validation of callback functions (and corresponding arguments) in NumericalIntegration
We need a method (or methods) to validate the inputs for our approximation techniques when callback functions are used to generate the points used in the approximation.
In the method functionToPoints(), we evaluate the callback function at equally spaced points (x values) generated by ours $args input ($start, $end, and $n). However, if the callback function is not continuous (for example, f(x) = 1/x), we will get errors.
We also need to verify that $start and $end are numbers, that $start < $end, and that $n > 1 is an integer.
To verify numbers, you can type hint $n as an int, and start and end as int if appropriate, otherwise as float I would think.
For the verification of values, you might take a look at Math\Functions\Support::checkLimits. The probability distributions all make use of this. They define their parameter limits in ISO 31-11 format and the function validates if the values are within the predefined limits.
In this case, it might be a bit much to dynamically create the strings of the limits and have the Support::checkLimits function take care of it. Might just make a local private method to do it. But you might want to take a look at the Support::checkLimits in case you find a use for it elsewhere.
For validating the points of the callback, do you mean they must be discrete values (integers)? If so, then you could do something tricky like:
if (count(array_filter(array_map('is_int', $ys))) !== $n) { ... }
That will map is_int over an array of y values, filter out any false values (non integers) and compare that count to n.