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

Commit 8c50eec

Browse files
authored
Merge pull request #76 from programmatordev/YAPV-69-refactor-error-messages
Refactor error messages
2 parents 19ddb26 + adf2c8b commit 8c50eec

File tree

87 files changed

+283
-325
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+283
-325
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ $validator = Validator::type('int')->greaterThanOrEqual(18);
3030

3131
// and validate with these:
3232
$validator->validate(16); // returns bool: false
33-
$validator->assert(16, 'age'); // throws exception: The age value should be greater than or equal to 18, 16 given.
33+
$validator->assert(16, 'age'); // throws exception: The age value should be greater than or equal to 18.
3434
```
3535

3636
## Documentation

docs/01-get-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ $validator = Validator::type('int')->greaterThanOrEqual(18);
2828

2929
// and validate with these:
3030
$validator->validate(16); // returns bool: false
31-
$validator->assert(16, 'age'); // throws exception: The age value should be greater than or equal to 18, 16 given.
31+
$validator->assert(16, 'age'); // throws exception: The age value should be greater than or equal to 18.
3232
```

docs/03-rules_blank.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Validator::blank(normalizer: fn($value) => trim($value))->validate(' '); // true
4040

4141
### `message`
4242

43-
type: `?string` default: `The {{ name }} value should be blank, {{ value }} given.`
43+
type: `?string` default: `The {{ name }} value should be blank.`
4444

4545
Message that will be shown if the value is not blank.
4646

docs/03-rules_choice.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ Validator::choice(['red', 'green', 'blue'], multiple: true, min: 2, max: 3)->val
4242
> [!NOTE]
4343
> An `UnexpectedValueException` will be thrown when `multiple` is `true` and the input value is not an `array`.
4444
45-
> [!NOTE]
46-
> An `UnexpectedValueException` will be thrown when the `min` value is greater than or equal to the `max` value.
47-
4845
## Options
4946

5047
### `constraints`
@@ -78,7 +75,7 @@ For example, if `max` is 2, the input array must have at most 2 values.
7875

7976
### `message`
8077

81-
type: `?string` default: `The {{ name }} value is not a valid choice, {{ value }} given. Accepted values are: {{ constraints }}.`
78+
type: `?string` default: `The {{ name }} value is not a valid choice. Accepted values are: {{ constraints }}.`
8279

8380
Message that will be shown if input value is not a valid choice.
8481

@@ -92,7 +89,7 @@ The following parameters are available:
9289

9390
### `multipleMessage`
9491

95-
type: `?string` default: `The {{ name }} value has one or more invalid choices, {{ value }} given. Accepted values are: {{ constraints }}.`
92+
type: `?string` default: `The {{ name }} value has one or more invalid choices. Accepted values are: {{ constraints }}.`
9693

9794
Message that will be shown when `multiple` is `true` and at least one of the input array values is not a valid choice.
9895

@@ -106,7 +103,7 @@ The following parameters are available:
106103

107104
### `minMessage`
108105

109-
type: `?string` default: `The {{ name }} value must have at least {{ min }} choices, {{ numElements }} choices given.`
106+
type: `?string` default: `The {{ name }} value must have at least {{ min }} choice(s).`
110107

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

@@ -123,7 +120,7 @@ The following parameters are available:
123120

124121
### `maxMessage`
125122

126-
type: `?string` default: `The {{ name }} value must have at most {{ max }} choices, {{ numElements }} choices given.`
123+
type: `?string` default: `The {{ name }} value must have at most {{ max }} choice(s).`
127124

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

docs/03-rules_count.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ Validator::count(min: 3, max: 3)->validate(['a', 'b', 'c']); // true
3232
> [!NOTE]
3333
> An `UnexpectedValueException` will be thrown when either `min` or `max` options are not given.
3434
35-
> [!NOTE]
36-
> An `UnexpectedValueException` will be thrown when the `min` value is greater than the `max` value.
37-
3835
> [!NOTE]
3936
> An `UnexpectedValueException` will be thrown when the input value is not an `array` or an object implementing `\Countable`.
4037
@@ -54,7 +51,7 @@ It defines the maximum number of elements required.
5451

5552
### `minMessage`
5653

57-
type: `?string` default: `The {{ name }} value should contain {{ min }} elements or more, {{ numElements }} elements given.`
54+
type: `?string` default: `The {{ name }} value should contain {{ min }} elements or more.`
5855

5956
Message that will be shown when the input value has fewer elements than the defined in `min`.
6057

@@ -70,7 +67,7 @@ The following parameters are available:
7067

7168
### `maxMessage`
7269

73-
type: `?string` default: `The {{ name }} value should contain {{ max }} elements or less, {{ numElements }} elements given.`
70+
type: `?string` default: `The {{ name }} value should contain {{ max }} elements or less.`
7471

7572
Message that will be shown when the input value has more elements than the defined in `max`.
7673

@@ -86,7 +83,7 @@ The following parameters are available:
8683

8784
### `exactMessage`
8885

89-
type: `?string` default: `The {{ name }} value should contain exactly {{ min }} elements, {{ numElements }} elements given.`
86+
type: `?string` default: `The {{ name }} value should contain exactly {{ min }} elements.`
9087

9188
Message that will be shown when `min` and `max` options have the same value and the input value has a different number of elements.
9289

docs/03-rules_country.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Available options:
4141

4242
### `message`
4343

44-
type: `?string` default: `The {{ name }} value is not a valid country, {{ value }} given.`
44+
type: `?string` default: `The {{ name }} value is not a valid country.`
4545

4646
Message that will be shown if the input value is not a valid country code.
4747

docs/03-rules_each-key.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ Validator that will validate each key of an `array` or object implementing `\Tra
3434

3535
### `message`
3636

37-
type: `?string` default: `Invalid key: {{ message }}`
37+
type: `?string` default: `Invalid key {{ key }}: {{ message }}`
3838

3939
Message that will be shown if at least one input value key is invalid according to the given `validator`.
4040

4141
```php
42-
// Throws: Invalid key: The color key value should be of type "string", 1 given.
42+
// throws: Invalid key 1: The value should be of type "string".
4343
Validator::eachKey(
4444
Validator::type('string')
4545
)->assert(['red' => '#f00', 1 => '#0f0'], 'color');

docs/03-rules_each-value.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type: `?string` default: `At key "{{ key }}": {{ message }}`
3939
Message that will be shown if at least one input value element is invalid according to the given `validator`.
4040

4141
```php
42-
// Throws: At key 2: The color value should not be blank, "" given.
42+
// throws: At key 2: The color value should not be blank.
4343
Validator::eachValue(
4444
Validator::notBlank()
4545
)->assert(['red', 'green', ''], 'color');

docs/03-rules_email.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Validator::email(normalizer: fn($value) => trim($value))->validate('test@example
5656

5757
### `message`
5858

59-
type: `?string` default: `The {{ name }} value is not a valid email address, {{ value }} given.`
59+
type: `?string` default: `The {{ name }} value is not a valid email address.`
6060

6161
Message that will be shown if the input value is not a valid email address.
6262

docs/03-rules_greater-than-or-equal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Can be a `string`, `int`, `float` or `DateTimeInterface` object.
4444

4545
### `message`
4646

47-
type: `?string` default: `The {{ name }} value should be greater than or equal to {{ constraint }}, {{ value }} given.`
47+
type: `?string` default: `The {{ name }} value should be greater than or equal to {{ constraint }}.`
4848

4949
Message that will be shown if the value is not greater than or equal to the constraint value.
5050

0 commit comments

Comments
 (0)