Skip to content

Commit 98cd28f

Browse files
committed
Replace isValid() calls with assert()
There's more value on showing how `assert()` displays the validation messages than simply showing if `isValid()` returns `true` or `false`. However, that increases the chances of having outdated documentation, so I created a console command that updates the Markdown files with the correct message.
1 parent 6022914 commit 98cd28f

172 files changed

Lines changed: 2163 additions & 672 deletions

File tree

Some content is hidden

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

.github/workflows/continuous-integration.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,24 @@ jobs:
9292

9393
- name: Run PHPStan
9494
run: vendor/bin/phpstan analyze
95+
96+
doc-check:
97+
name: Documentation Check
98+
99+
runs-on: ubuntu-latest
100+
101+
steps:
102+
- name: Checkout
103+
uses: actions/checkout@v6
104+
105+
- name: Install PHP
106+
uses: shivammathur/setup-php@v2
107+
with:
108+
php-version: 8.5
109+
coverage: none
110+
111+
- name: Install dependencies
112+
run: composer install --prefer-dist
113+
114+
- name: Run doc:assertions
115+
run: bin/console update:doc:assertions

bin/console

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ declare(strict_types=1);
1111
require __DIR__ . '/../vendor/autoload.php';
1212

1313
use Respect\Dev\Commands\CreateMixinCommand;
14+
use Respect\Dev\Commands\UpdateDocAssertionCommand;
1415
use Respect\Dev\Commands\UpdateDocLinksCommand;
1516
use Respect\Dev\Commands\UpdateDomainSuffixesCommand;
1617
use Respect\Dev\Commands\UpdateDomainToplevelCommand;
@@ -20,6 +21,7 @@ use Symfony\Component\Console\Application;
2021
return (static function () {
2122
$application = new Application('Respect/Validation', '3.0');
2223
$application->addCommand(new CreateMixinCommand());
24+
$application->addCommand(new UpdateDocAssertionCommand());
2325
$application->addCommand(new UpdateDocLinksCommand());
2426
$application->addCommand(new UpdateDomainSuffixesCommand());
2527
$application->addCommand(new UpdateDomainToplevelCommand());

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"psr/http-message": "^1.0 || ^2.0",
4242
"ramsey/uuid": "^4",
4343
"respect/coding-standard": "^5.0",
44+
"sebastian/diff": "^7.0",
4445
"sokil/php-isocodes": "^4.2.1",
4546
"sokil/php-isocodes-db-only": "^4.0",
4647
"squizlabs/php_codesniffer": "^4.0",

docs/concrete-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Concrete API
22

33
There are many micro-frameworks that rely on magic methods. We don't. In this
4-
document we're gonna explore the Respect\Validation API without fluent interfaces
4+
document we're going to explore the Respect\Validation API without fluent interfaces
55
or magic methods. We'll use a traditional dependency injection approach.
66

77
```php

docs/custom-validators.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class Something extends Simple
2727
}
2828
```
2929

30-
The `'{{subject}} is not something` message would be used then you call the validator
30+
The `'{{subject}} is not something` message would be used when you call the validator
3131
with the `not()`.
3232

3333
All classes in Validation are created by the `Factory` class. If you want

docs/list-of-validators-by-category.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@
298298
- [ScalarVal](validators/ScalarVal.md)
299299
- [StringType](validators/StringType.md)
300300
- [StringVal](validators/StringVal.md)
301-
- [Type](validators/Type.md)
302301

303302
## Alphabetically
304303

@@ -449,7 +448,6 @@
449448
- [Time](validators/Time.md)
450449
- [Tld](validators/Tld.md)
451450
- [TrueVal](validators/TrueVal.md)
452-
- [Type](validators/Type.md)
453451
- [Undef](validators/Undef.md)
454452
- [UndefOr](validators/UndefOr.md)
455453
- [Unique](validators/Unique.md)

docs/validators/All.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
Validates all items of the input against a given validator.
66

77
```php
8-
v::all(v::intType())->isValid([1, 2, 3]); // true
9-
v::all(v::intType())->isValid([1, 2, '3']); // false
8+
v::all(v::intType())->assert([1, 2, 3]);
9+
// Validation passes successfully
10+
11+
v::all(v::intType())->assert([1, 2, '3']);
12+
// → Every item in `[1, 2, "3"]` must be an integer
1013
```
1114

1215
This validator is similar to [Each](Each.md), but as opposed to the former, it displays a single message when asserting an input.
@@ -28,10 +31,10 @@ This template serve as message prefixes.:
2831

2932
```php
3033
v::all(v::floatType())->assert([1.5, 2]);
31-
// Message: Every item in `[1.5, 2]` must be float
34+
// Every item in `[1.5, 2]` must be float
3235

3336
v::not(v::all(v::intType()))->assert([1, 2, -3]);
34-
// Message: Every item in `[1, 2, -3]` must not be an integer
37+
// Every item in `[1, 2, -3]` must not be an integer
3538
```
3639

3740
## Categorization

docs/validators/AllOf.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
Will validate if all inner validators validates.
66

77
```php
8-
v::allOf(v::intVal(), v::positive())->isValid(15); // true
8+
v::allOf(v::intVal(), v::positive())->assert(15);
9+
// Validation passes successfully
910
```
1011

1112
## Templates

docs/validators/Alnum.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,28 @@ Alphanumeric is a combination of alphabetic (a-z and A-Z) and numeric (0-9)
99
characters.
1010

1111
```php
12-
v::alnum()->isValid('foo 123'); // false
13-
v::alnum(' ')->isValid('foo 123'); // true
14-
v::alnum()->isValid('100%'); // false
15-
v::alnum('%')->isValid('100%'); // true
16-
v::alnum('%', ',')->isValid('10,5%'); // true
12+
v::alnum()->assert('foo 123');
13+
// → "foo 123" must contain only letters (a-z) and digits (0-9)
14+
15+
v::alnum(' ')->assert('foo 123');
16+
// Validation passes successfully
17+
18+
v::alnum()->assert('100%');
19+
// → "100%" must contain only letters (a-z) and digits (0-9)
20+
21+
v::alnum('%')->assert('100%');
22+
// Validation passes successfully
23+
24+
v::alnum('%', ',')->assert('10,5%');
25+
// Validation passes successfully
1726
```
1827

1928
You can restrict case using the [Lowercase](Lowercase.md) and
2029
[Uppercase](Uppercase.md) validators.
2130

2231
```php
23-
v::alnum()->uppercase()->isValid('example'); // false
32+
v::alnum()->uppercase()->assert('example');
33+
// → "example" must contain only uppercase letters
2434
```
2535

2636
Message template for this validator includes `{{additionalChars}}` as the string

docs/validators/Alpha.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,28 @@ Validates whether the input contains only alphabetic characters. This is similar
77
to [Alnum](Alnum.md), but it does not allow numbers.
88

99
```php
10-
v::alpha()->isValid('some name'); // false
11-
v::alpha(' ')->isValid('some name'); // true
12-
v::alpha()->isValid('Cedric-Fabian'); // false
13-
v::alpha('-')->isValid('Cedric-Fabian'); // true
14-
v::alpha('-', '\'')->isValid('\'s-Gravenhage'); // true
10+
v::alpha()->assert('some name');
11+
// → "some name" must contain only letters (a-z)
12+
13+
v::alpha(' ')->assert('some name');
14+
// Validation passes successfully
15+
16+
v::alpha()->assert('Cedric-Fabian');
17+
// → "Cedric-Fabian" must contain only letters (a-z)
18+
19+
v::alpha('-')->assert('Cedric-Fabian');
20+
// Validation passes successfully
21+
22+
v::alpha('-', '\'')->assert('\'s-Gravenhage');
23+
// Validation passes successfully
1524
```
1625

1726
You can restrict case using the [Lowercase](Lowercase.md) and
1827
[Uppercase](Uppercase.md) validators.
1928

2029
```php
21-
v::alpha()->uppercase()->isValid('example'); // false
30+
v::alpha()->uppercase()->assert('example');
31+
// → "example" must contain only uppercase letters
2232
```
2333

2434
## Templates

0 commit comments

Comments
 (0)