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

Commit c16d183

Browse files
committed
chore: added condition to check if max constraint is greater than min constraint
1 parent 0f21ca0 commit c16d183

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/Rule/Range.php

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

55
use ProgrammatorDev\YetAnotherPhpValidator\Exception\RangeException;
6-
use ProgrammatorDev\YetAnotherPhpValidator\Exception\ValidationException;
6+
use ProgrammatorDev\YetAnotherPhpValidator\Exception\UnexpectedValueException;
77
use ProgrammatorDev\YetAnotherPhpValidator\Rule\Util\AssertIsComparableTrait;
88
use ProgrammatorDev\YetAnotherPhpValidator\Validator;
99
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -35,13 +35,13 @@ public function assert(mixed $value, string $name): void
3535
{
3636
$this->assertIsComparable($this->minConstraint, $this->maxConstraint);
3737

38-
try {
39-
Validator
40-
::greaterThanOrEqual($this->minConstraint)
41-
->lessThanOrEqual($this->maxConstraint)
42-
->assert($value, $name);
38+
if (!Validator::greaterThan($this->minConstraint)->validate($this->maxConstraint)) {
39+
throw new UnexpectedValueException(
40+
'Max constraint value must be greater than min constraint value.'
41+
);
4342
}
44-
catch (ValidationException) {
43+
44+
if (!Validator::greaterThanOrEqual($this->minConstraint)->lessThanOrEqual($this->maxConstraint)->validate($value)) {
4545
throw new RangeException(
4646
message: $this->options['message'],
4747
parameters: [

0 commit comments

Comments
 (0)