Assert\Assertion::range PHP Method

range() public static method

Assert that value is in range of numbers.
public static range ( mixed $value, integer $minValue, integer $maxValue, string | null $message = null, string | null $propertyPath = null ) : boolean
$value mixed
$minValue integer
$maxValue integer
$message string | null
$propertyPath string | null
return boolean
    public static function range($value, $minValue, $maxValue, $message = null, $propertyPath = null)
    {
        static::numeric($value, $message, $propertyPath);
        if ($value < $minValue || $value > $maxValue) {
            $message = sprintf($message ?: 'Number "%s" was expected to be at least "%d" and at most "%d".', static::stringify($value), static::stringify($minValue), static::stringify($maxValue));
            throw static::createException($value, $message, static::INVALID_RANGE, $propertyPath, array('min' => $minValue, 'max' => $maxValue));
        }
        return true;
    }

Usage Example

 /**
  * Set the radius in meters.
  *
  * @param int $meters
  *
  * @return self
  */
 public function setRadius($meters)
 {
     Assertion::integer($meters);
     Assertion::range($meters, 1, 100000);
     $this->radius = $meters;
     return $this;
 }
All Usage Examples Of Assert\Assertion::range