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

Commit 579c7d4

Browse files
committed
chore: misc documentation improvements
1 parent ed03860 commit 579c7d4

10 files changed

+27
-22
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
Versatile validator focused on validating development code with expressive error messages.
44

55
> **Note**
6-
> This library is not in version 1.x mainly because there are so few available rules.
7-
> Hopefully, that should change in the near future.
6+
> This library is not in version 1.x mainly because there are few available rules.
7+
> Hopefully, that will change in the near future.
88
99
## Requirements
1010

@@ -59,7 +59,7 @@ $validator->assert(16, 'Age'); // throws exception: The "Age" value should be gr
5959

6060
## Contributing
6161

62-
Any form of contribution to improve this library will be welcome and appreciated.
62+
Any form of contribution to improve this library (including requests) will be welcome and appreciated.
6363
Make sure to open a pull request or issue.
6464

6565
## Acknowledgments

docs/02-usage.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ function calculateDiscount(float $price, float $discount, string $type): float
187187
188188
## Error Handling
189189

190-
When using the [`assert`](#assert) method to validate a value, an exception is thrown when a rule fails.
190+
When using the [`assert`](#assert) method, an exception is thrown when a rule fails.
191191

192-
Each rule has a unique exception, formed by the name of the rule followed by the work Exception `RuleNameException`.
192+
Each rule has a unique exception, formed by the name of the rule followed by the word Exception, like `RuleNameException`.
193193
The following shows an example:
194194

195195
```php
@@ -225,10 +225,12 @@ try {
225225
}
226226
catch (ValidationException $exception) {
227227
// Do something when a rule fails
228+
echo $exception->getMessage();
228229
}
229230
```
230231

231-
When using both the [`assert`](#assert) or [`validate`](#validate) methods, an `UnexpectedValueException` is thrown when the provided input data is not valid to perform the validation.
232+
When using both the [`assert`](#assert) or [`validate`](#validate) methods,
233+
an `UnexpectedValueException` is thrown when the provided input data is not valid to perform the validation.
232234

233235
For example, when trying to compare a date with a string:
234236

@@ -262,5 +264,5 @@ Validator::choice(
262264
message: '"{{ value }}" is not a valid {{ name }}! You must select one of {{ constraints }}.'
263265
)->assert('yellow', 'color');
264266

265-
// "yellow" is not a valid color! You must select one of [red, green, blue].
267+
// Throws: "yellow" is not a valid color! You must select one of [red, green, blue].
266268
```

docs/03x-rules-choice.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Validator::choice(['red', 'green', 'blue'], multiple: true, minConstraint: 2, ma
5151

5252
type: `array` `required`
5353

54-
Collection of choices to be validated against the input value.
54+
Collection of constraint choices to be validated against the input value.
5555

5656
### `multiple`
5757

docs/03x-rules-greater-than-or-equal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Validator::greaterThanOrEqual(new DateTime('today'))->validate(new DateTime('tod
2727
```
2828

2929
> **Note**
30-
> String comparison is case-sensitive, meaning that comparing `'hello'` with `'Hello'` is different.
30+
> String comparison is case-sensitive, meaning that comparing `"hello"` with `"Hello"` is different.
3131
> Check [`strcmp`](https://www.php.net/manual/en/function.strcmp.php) for more information.
3232
3333
> **Note**

docs/03x-rules-greater-than.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Validator::greaterThan(new DateTime('today'))->validate(new DateTime('today'));
2727
```
2828

2929
> **Note**
30-
> String comparison is case-sensitive, meaning that comparing `'hello'` with `'Hello'` is different.
30+
> String comparison is case-sensitive, meaning that comparing `"hello"` with `"Hello"` is different.
3131
> Check [`strcmp`](https://www.php.net/manual/en/function.strcmp.php) for more information.
3232
3333
> **Note**

docs/03x-rules-less-than-or-equal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Validator::lessThanOrEqual(new DateTime('today'))->validate(new DateTime('today'
2727
```
2828

2929
> **Note**
30-
> String comparison is case-sensitive, meaning that comparing `'hello'` with `'Hello'` is different.
30+
> String comparison is case-sensitive, meaning that comparing `"hello"` with `"Hello"` is different.
3131
> Check [`strcmp`](https://www.php.net/manual/en/function.strcmp.php) for more information.
3232
3333
> **Note**

docs/03x-rules-less-than.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Validator::lessThan(new DateTime('today'))->validate(new DateTime('today')); //
2727
```
2828

2929
> **Note**
30-
> String comparison is case-sensitive, meaning that comparing `'hello'` with `'Hello'` is different.
30+
> String comparison is case-sensitive, meaning that comparing `"hello"` with `"Hello"` is different.
3131
> Check [`strcmp`](https://www.php.net/manual/en/function.strcmp.php) for more information.
3232
3333
> **Note**

docs/03x-rules-not-blank.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ NotBlank(
1111

1212
## Basic Usage
1313

14-
Bellow are the only cases where the rule will fail, everything else is considered valid
15-
(you may want to check the [`normalizer`](#normalizer) option for a different behaviour):
14+
Bellow are the only cases where the rule will fail,
15+
everything else is considered valid (you may want to check the [`normalizer`](#normalizer) option for a different behaviour):
1616

1717
```php
1818
Validator::notBlank()->validate(''); // false
@@ -29,7 +29,7 @@ type: `callable` default: `null`
2929

3030
Allows to define a `callable` that will be applied to the value before checking if it is valid.
3131

32-
For example, use `trim`, or pass your own function, to now allow a string with whitespaces only:
32+
For example, use `trim`, or pass your own function, to not allow a string with whitespaces only:
3333

3434
```php
3535
// Existing PHP callables

docs/03x-rules-range.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Range(
1313

1414
## Basic Usage
1515

16-
Values equal to the defined minimum and maximum constraints are considered valid.
16+
Values equal to the defined minimum and maximum values are considered valid.
1717

1818
```php
1919
Validator::range(1, 20)->validate(10); // true
@@ -30,7 +30,7 @@ Validator::range(new DateTime('yesterday'), new DateTime('tomorrow'))->validate(
3030
```
3131

3232
> **Note**
33-
> String comparison is case-sensitive, meaning that comparing `'hello'` with `'Hello'` is different.
33+
> String comparison is case-sensitive, meaning that comparing `"hello"` with `"Hello"` is different.
3434
> Check [`strcmp`](https://www.php.net/manual/en/function.strcmp.php) for more information.
3535
3636
> **Note**
@@ -60,7 +60,6 @@ Can be a `string`, `int`, `float` or `DateTimeInterface` object.
6060
type: `string` default: `The "{{ name }}" value should be between "{{ minConstraint }}" and "{{ maxConstraint }}", "{{ value }}" given.`
6161

6262
Message that will be shown if the value is not between the minimum and maximum constraint values.
63-
Check the [Custom Messages]() section for more information.
6463

6564
The following parameters are available:
6665

docs/04-custom-rules.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CustomRuleException extends ValidationException {}
2222
...then create your custom rule class...
2323

2424
```php
25-
namespace My\Project\Rules;
25+
namespace My\Project\Rule;
2626

2727
use ProgrammatorDev\YetAnotherPhpValidator\Rule\AbstractRule;
2828
use ProgrammatorDev\YetAnotherPhpValidator\Rule\RuleInterface;
@@ -88,6 +88,10 @@ This means that you can have dynamic content in your messages.
8888
To make it work, just pass an associative array with the name and value of your parameters, and they will be available in the message:
8989

9090
```php
91+
// Exception
92+
class FavoriteException extends ValidationException {}
93+
94+
// Rule
9195
class Favorite extends AbstractRule implements RuleInterface
9296
{
9397
public function __construct(
@@ -100,9 +104,9 @@ class Favorite extends AbstractRule implements RuleInterface
100104
throw new FavoriteException(
101105
message: 'My favorite {{ name }} is "{{ favorite }}", not "{{ value }}"!',
102106
parameters: [
103-
'name' => $name,
104-
'favorite' => $this->favorite,
105-
'value' => $value
107+
'name' => $name, // {{ name }}
108+
'favorite' => $this->favorite, // {{ favorite }}
109+
'value' => $value // {{ value }}
106110
]
107111
)
108112
}

0 commit comments

Comments
 (0)