This PR adds a new helper trait called the ValidatorTrait to validate variables in ways that I find myself having to write manually over and over and over again. It will throw a special InvalidVariableException class to be thrown if the validation is unsuccessful.
Please check that it is fully unit tested.
It has the following public methods:
checkNumeric() - Checks that a value of any scalar type is numeric
checkWholeNumber() - Checks that a value of any scalar type is a whole number
checkScalar() - Checks that a value is scalar, i.e. can be cast to a string. In this instance, null counts as scalar, even though the is_scalar() function does not allow for it
checkInstance() - Checks that a value is an instance of a class or interface
This PR adds a new helper trait called the
ValidatorTrait
to validate variables in ways that I find myself having to write manually over and over and over again. It will throw a specialInvalidVariableException
class to be thrown if the validation is unsuccessful.Please check that it is fully unit tested.
It has the following public methods:
checkNumeric()
- Checks that a value of any scalar type is numericcheckWholeNumber()
- Checks that a value of any scalar type is a whole numbercheckScalar()
- Checks that a value is scalar, i.e. can be cast to a string. In this instance,null
counts as scalar, even though theis_scalar()
function does not allow for itcheckInstance()
- Checks that a value is an instance of a class or interface