Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 0f21ca0

Browse files
committed
feat: added Range rule
1 parent c7ec104 commit 0f21ca0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Rule/Range.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace ProgrammatorDev\YetAnotherPhpValidator\Rule;
44

55
use ProgrammatorDev\YetAnotherPhpValidator\Exception\RangeException;
6+
use ProgrammatorDev\YetAnotherPhpValidator\Exception\ValidationException;
67
use ProgrammatorDev\YetAnotherPhpValidator\Rule\Util\AssertIsComparableTrait;
78
use ProgrammatorDev\YetAnotherPhpValidator\Validator;
89
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -34,7 +35,13 @@ public function assert(mixed $value, string $name): void
3435
{
3536
$this->assertIsComparable($this->minConstraint, $this->maxConstraint);
3637

37-
if (!Validator::greaterThan($this->minConstraint)->lessThan($this->maxConstraint)->validate($value)) {
38+
try {
39+
Validator
40+
::greaterThanOrEqual($this->minConstraint)
41+
->lessThanOrEqual($this->maxConstraint)
42+
->assert($value, $name);
43+
}
44+
catch (ValidationException) {
3845
throw new RangeException(
3946
message: $this->options['message'],
4047
parameters: [

0 commit comments

Comments
 (0)