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

Commit c010641

Browse files
committed
chore: changed choice numValues parameter to numElements
1 parent 31a72cd commit c010641

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

docs/03-rules_choice.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Choice(
1010
?int $max = null,
1111
string $message = 'The {{ name }} value is not a valid choice, {{ value }} given. Accepted values are: {{ constraints }}.',
1212
string $multipleMessage = 'The {{ name }} value has one or more invalid choices, {{ value }} given. Accepted values are: {{ constraints }}.',
13-
string $minMessage = 'The {{ name }} value must have at least {{ min }} choices, {{ numValues }} choices given.',
14-
string $maxMessage = 'The {{ name }} value must have at most {{ max }} choices, {{ numValues }} choices given.'
13+
string $minMessage = 'The {{ name }} value must have at least {{ min }} choices, {{ numElements }} choices given.',
14+
string $maxMessage = 'The {{ name }} value must have at most {{ max }} choices, {{ numElements }} choices given.'
1515
);
1616
```
1717

@@ -106,37 +106,37 @@ The following parameters are available:
106106

107107
### `minMessage`
108108

109-
type: `string` default: `The {{ name }} value must have at least {{ min }} choices, {{ numValues }} choices given.`
109+
type: `string` default: `The {{ name }} value must have at least {{ min }} choices, {{ numElements }} choices given.`
110110

111111
Message that will be shown when `multiple` is `true` and input array has fewer values than the defined in `min`.
112112

113113
The following parameters are available:
114114

115-
| Parameter | Description |
116-
|---------------------|--------------------------------------|
117-
| `{{ value }}` | The current invalid value |
118-
| `{{ numValues }}` | The current invalid number of values |
119-
| `{{ name }}` | Name of the invalid value |
120-
| `{{ constraints }}` | The array of valid choices |
121-
| `{{ min }}` | The minimum number of valid choices |
122-
| `{{ max }}` | The maximum number of valid choices |
115+
| Parameter | Description |
116+
|---------------------|----------------------------------------|
117+
| `{{ value }}` | The current invalid value |
118+
| `{{ name }}` | Name of the invalid value |
119+
| `{{ constraints }}` | The array of valid choices |
120+
| `{{ min }}` | The minimum number of valid choices |
121+
| `{{ max }}` | The maximum number of valid choices |
122+
| `{{ numElements }}` | The current invalid number of elements |
123123

124124
### `maxMessage`
125125

126-
type: `string` default: `The {{ name }} value must have at most {{ max }} choices, {{ numValues }} choices given.`
126+
type: `string` default: `The {{ name }} value must have at most {{ max }} choices, {{ numElements }} choices given.`
127127

128128
Message that will be shown when `multiple` is `true` and input array has more values than the defined in `max`.
129129

130130
The following parameters are available:
131131

132-
| Parameter | Description |
133-
|---------------------|--------------------------------------|
134-
| `{{ value }}` | The current invalid value |
135-
| `{{ numValues }}` | The current invalid number of values |
136-
| `{{ name }}` | Name of the invalid value |
137-
| `{{ constraints }}` | The array of valid choices |
138-
| `{{ min }}` | The minimum number of valid choices |
139-
| `{{ max }}` | The maximum number of valid choices |
132+
| Parameter | Description |
133+
|---------------------|----------------------------------------|
134+
| `{{ value }}` | The current invalid value |
135+
| `{{ name }}` | Name of the invalid value |
136+
| `{{ constraints }}` | The array of valid choices |
137+
| `{{ min }}` | The minimum number of valid choices |
138+
| `{{ max }}` | The maximum number of valid choices |
139+
| `{{ numElements }}` | The current invalid number of elements |
140140

141141
## Changelog
142142

src/ChainedValidatorInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public function choice(
1414
?int $max = null,
1515
string $message = 'The {{ name }} value is not a valid choice, {{ value }} given. Accepted values are: {{ constraints }}.',
1616
string $multipleMessage = 'The {{ name }} value has one or more invalid choices, {{ value }} given. Accepted values are: {{ constraints }}.',
17-
string $minMessage = 'The {{ name }} value must have at least {{ min }} choices, {{ numValues }} choices given.',
18-
string $maxMessage = 'The {{ name }} value must have at most {{ max }} choices, {{ numValues }} choices given.'
17+
string $minMessage = 'The {{ name }} value must have at least {{ min }} choices, {{ numElements }} choices given.',
18+
string $maxMessage = 'The {{ name }} value must have at most {{ max }} choices, {{ numElements }} choices given.'
1919
): ChainedValidatorInterface&Validator;
2020

2121
public function country(

src/Rule/Choice.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public function __construct(
1515
private readonly ?int $max = null,
1616
private readonly string $message = 'The {{ name }} value is not a valid choice, {{ value }} given. Accepted values are: {{ constraints }}.',
1717
private readonly string $multipleMessage = 'The {{ name }} value has one or more invalid choices, {{ value }} given. Accepted values are: {{ constraints }}.',
18-
private readonly string $minMessage = 'The {{ name }} value must have at least {{ min }} choices, {{ numValues }} choices given.',
19-
private readonly string $maxMessage = 'The {{ name }} value must have at most {{ max }} choices, {{ numValues }} choices given.'
18+
private readonly string $minMessage = 'The {{ name }} value must have at least {{ min }} choices, {{ numElements }} choices given.',
19+
private readonly string $maxMessage = 'The {{ name }} value must have at most {{ max }} choices, {{ numElements }} choices given.'
2020
) {}
2121

2222
public function assert(mixed $value, ?string $name = null): void
@@ -50,32 +50,32 @@ public function assert(mixed $value, ?string $name = null): void
5050
}
5151
}
5252

53-
$numValues = \count($value);
53+
$numElements = \count($value);
5454

55-
if ($this->min !== null && $numValues < $this->min) {
55+
if ($this->min !== null && $numElements < $this->min) {
5656
throw new ChoiceException(
5757
message: $this->minMessage,
5858
parameters: [
5959
'value' => $value,
60-
'numValues' => $numValues,
6160
'name' => $name,
6261
'constraints' => $this->constraints,
6362
'min' => $this->min,
64-
'max' => $this->max
63+
'max' => $this->max,
64+
'numElements' => $numElements
6565
]
6666
);
6767
}
6868

69-
if ($this->max !== null && $numValues > $this->max) {
69+
if ($this->max !== null && $numElements > $this->max) {
7070
throw new ChoiceException(
7171
message: $this->maxMessage,
7272
parameters: [
7373
'value' => $value,
74-
'numValues' => $numValues,
7574
'name' => $name,
7675
'constraints' => $this->constraints,
7776
'min' => $this->min,
78-
'max' => $this->max
77+
'max' => $this->max,
78+
'numElements' => $numElements
7979
]
8080
);
8181
}

src/StaticValidatorInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public static function choice(
1313
?int $max = null,
1414
string $message = 'The {{ name }} value is not a valid choice, {{ value }} given. Accepted values are: {{ constraints }}.',
1515
string $multipleMessage = 'The {{ name }} value has one or more invalid choices, {{ value }} given. Accepted values are: {{ constraints }}.',
16-
string $minMessage = 'The {{ name }} value must have at least {{ min }} choices, {{ numValues }} choices given.',
17-
string $maxMessage = 'The {{ name }} value must have at most {{ max }} choices, {{ numValues }} choices given.'
16+
string $minMessage = 'The {{ name }} value must have at least {{ min }} choices, {{ numElements }} choices given.',
17+
string $maxMessage = 'The {{ name }} value must have at most {{ max }} choices, {{ numElements }} choices given.'
1818
): ChainedValidatorInterface&Validator;
1919

2020
public static function country(

0 commit comments

Comments
 (0)