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

Commit 9d0acb8

Browse files
committed
chore: few code improvements
1 parent f550c97 commit 9d0acb8

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/Rule/Choice.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function assert(mixed $value, string $name): void
3939
{
4040
if ($this->multiple && !\is_array($value)) {
4141
throw new UnexpectedValueException(
42-
\sprintf('Expected value of type "array" when multiple, "%s" given', get_debug_type($value))
42+
\sprintf('Expected value of type "array" when using multiple choices, "%s" given', get_debug_type($value))
4343
);
4444
}
4545

src/Rule/Range.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ public function __construct(
2222
{
2323
$resolver = new OptionsResolver();
2424

25-
$resolver->setDefaults([
26-
'message' => 'The "{{ name }}" value should be between "{{ minConstraint }}" and "{{ maxConstraint }}", "{{ value }}" given.'
27-
]);
25+
$resolver->setDefaults(['message' => 'The "{{ name }}" value should be between "{{ minConstraint }}" and "{{ maxConstraint }}", "{{ value }}" given.']);
2826

2927
$resolver->setAllowedTypes('message', 'string');
3028

@@ -35,13 +33,22 @@ public function assert(mixed $value, string $name): void
3533
{
3634
$this->assertIsComparable($this->minConstraint, $this->maxConstraint);
3735

38-
if (!Validator::greaterThan($this->minConstraint)->validate($this->maxConstraint)) {
36+
if (
37+
!Validator
38+
::greaterThan($this->minConstraint)
39+
->validate($this->maxConstraint)
40+
) {
3941
throw new UnexpectedValueException(
4042
'Max constraint value must be greater than min constraint value.'
4143
);
4244
}
4345

44-
if (!Validator::greaterThanOrEqual($this->minConstraint)->lessThanOrEqual($this->maxConstraint)->validate($value)) {
46+
if (
47+
!Validator
48+
::greaterThanOrEqual($this->minConstraint)
49+
->lessThanOrEqual($this->maxConstraint)
50+
->validate($value)
51+
) {
4552
throw new RangeException(
4653
message: $this->options['message'],
4754
parameters: [

tests/ChoiceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ChoiceTest extends AbstractTest
1919
public static function provideRuleUnexpectedValueData(): \Generator
2020
{
2121
$constraints = [1, 2, 3, 4, 5];
22-
$multipleMessage = '/Expected value of type "array" when multiple, "(.*)" given/';
22+
$multipleMessage = '/Expected value of type "array" when using multiple choices, "(.*)" given/';
2323
$constraintMessage = '/Max constraint value must be greater than or equal to min constraint value./';
2424

2525
yield 'multiple not array' => [new Choice($constraints, true), 1, $multipleMessage];

0 commit comments

Comments
 (0)