Skip to content

Commit

Permalink
docs: improved examples
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepimpao committed Mar 25, 2024
1 parent a6a2e47 commit 990e81e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ Simple usage looks like:
use ProgrammatorDev\Validator\Rule;
use ProgrammatorDev\Validator\Validator;

// do this...
$validator = Validator::notBlank()->greaterThanOrEqual(18);
// do this:
$validator = Validator::type('int')->greaterThanOrEqual(18);

// ...and validate with these:
// and validate with these:
$validator->validate(16); // returns bool: false
$validator->assert(16, 'age'); // throws exception: The age value should be greater than or equal to 18, 16 given.
```
Expand Down
6 changes: 3 additions & 3 deletions docs/01-get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ Simple usage looks like:
use ProgrammatorDev\Validator\Rule;
use ProgrammatorDev\Validator\Validator;

// do this...
$validator = Validator::notBlank()->greaterThanOrEqual(18);
// do this:
$validator = Validator::type('int')->greaterThanOrEqual(18);

// ...and validate with these:
// and validate with these:
$validator->validate(16); // returns bool: false
$validator->assert(16, 'age'); // throws exception: The age value should be greater than or equal to 18, 16 given.
```
8 changes: 4 additions & 4 deletions docs/02-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function getWeather(float $latitude, float $longitude, string $unitSystem
{
Validator::range(-90, 90)->assert($latitude, 'latitude');
Validator::range(-180, 180)->assert($longitude, 'longitude');
Validator::notBlank()->choice(['metric', 'imperial'])->assert($unitSystem, 'unit system');
Validator::choice(['metric', 'imperial'])->assert($unitSystem, 'unit system');

// ...
}
Expand Down Expand Up @@ -51,7 +51,7 @@ function getWeather(float $latitude, float $longitude, string $unitSystem): floa
{
Validator::range(-90, 90)->assert($latitude, 'latitude');
Validator::range(-180, 180)->assert($longitude, 'longitude');
Validator::notBlank()->choice(['metric', 'imperial'])->assert($unitSystem, 'unit system');
Validator::choice(['metric', 'imperial'])->assert($unitSystem, 'unit system');

// ...
}
Expand Down Expand Up @@ -98,7 +98,7 @@ use ProgrammatorDev\Validator\Validator;
try {
Validator::range(-90, 90)->assert($latitude, 'latitude');
Validator::range(-180, 180)->assert($longitude, 'longitude');
Validator::notBlank()->choice(['metric', 'imperial'])->assert($unitSystem, 'unit system');
Validator::choice(['metric', 'imperial'])->assert($unitSystem, 'unit system');
}
catch (Exception\RangeException $exception) {
// do something when Range fails
Expand All @@ -120,7 +120,7 @@ use ProgrammatorDev\Validator\Validator;
try {
Validator::range(-90, 90)->assert($latitude, 'latitude');
Validator::range(-180, 180)->assert($longitude, 'longitude');
Validator::notBlank()->choice(['metric', 'imperial'])->assert($unitSystem, 'unit system');
Validator::choice(['metric', 'imperial'])->assert($unitSystem, 'unit system');
}
catch (ValidationException $exception) {
// do something when a rule fails
Expand Down

0 comments on commit 990e81e

Please sign in to comment.