diff --git a/src/Attribute/ContextField.php b/src/Attribute/ContextField.php index be963af..86f98ae 100644 --- a/src/Attribute/ContextField.php +++ b/src/Attribute/ContextField.php @@ -15,6 +15,8 @@ class ContextField public bool $mandatory = false, public ?int $minLength = null, public ?int $maxLength = null, + public ?int $minValue = null, + public ?int $maxValue = null, public ?string $regexFormat = null, public ?string $example = null, public mixed $default = null, @@ -27,14 +29,21 @@ class ContextField throw new MandatoryFieldException("Mandatory field must be provided a value."); } elseif ($value !== null) { - if ($this->minLength || $this->maxLength) { - if (is_string($value)) { - if (mb_strlen($value) < $this->minLength) { - throw new MinimumLengthException("Minimum {$this->minLength} string length is required."); - } - elseif (mb_strlen($value) > $this->maxLength) { - throw new MaximumLengthException("Maximum {$this->maxLength} string length has been exceeded."); - } + if (($this->minLength || $this->maxLength) && is_string($value)) { + if (mb_strlen($value) < $this->minLength) { + throw new MinimumLengthException("Minimum {$this->minLength} string length is required."); + } + elseif (mb_strlen($value) > $this->maxLength) { + throw new MaximumLengthException("Maximum {$this->maxLength} string length has been exceeded."); + } + } + + if (($this->minValue || $this->maxValue) && is_numeric($value)) { + if ($value < $this->minValue) { + throw new MinimumLengthException("Minimum value set at {$this->minValue}."); + } + elseif ($value > $this->maxValue) { + throw new MaximumLengthException("Maximum value set at {$this->maxValue}."); } }