gigili / good-food-tracker-api

Good food tracker - API
MIT License
6 stars 11 forks source link

[ FEATURE ] Extend validation class to support numeric value range validations #224

Open gigili opened 3 years ago

gigili commented 3 years ago

Is your feature request related to a problem? Please describe. When using the Validation class we have the ability to validate values to make sure they are of a numeric type, but we are missing options for validating if that value is also constrained in a certain range as well.

Describe the solution you'd like To have new ValidationRules such as ValidationRules::MINIMUM_VALUE, ValidationRules::MAXIMUM_VALUE, ValidationRules::IN_RANGE

Usage examples

Validation::validate([
  ["restaurantID" => [ValidationRules::REQUIRED, ValidationRules::VALID_UUID]],
  ["ratingID" => [
    ValidationRules::REQUIRED, 
    ValidationRules::NUMERIC, 
    [ValidationRules::MINIMUM_VALUE => 0],
    [ValidationRules::MAXIMUM_VALUE => 100],
    [ValidationRules::IN_RANGE => [0, 100]],
 ]
], $request);