Skip to content

Commit 2a7f345

Browse files
committed
Streamline validators.md index
Makes it so the index looks more like a cheatsheet, condensing information instead of making long lists that require lots of scrolling to explore. Additionally, the happy path for each validator was also added, providing a quick reference use for comparison. The direct markdown links were replaced by titled markdown references, offering mouse-over tooltips over links that display the validator one-line description. To ensure a proper source of truth for these new index goodies, the AssertionMessageLinter was modified to verify that the first assertion in each doc is a single-line validator that passes (a happy path), further making our documentation conventions more solid.
1 parent 68ed5d2 commit 2a7f345

27 files changed

+513
-498
lines changed

docs/validators.md

Lines changed: 346 additions & 439 deletions
Large diffs are not rendered by default.

docs/validators/Alnum.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ Alphanumeric is a combination of alphabetic (a-z and A-Z) and numeric (0-9)
1414
characters.
1515

1616
```php
17-
v::alnum()->assert('foo 123');
18-
// → "foo 123" must contain only letters (a-z) and digits (0-9)
19-
2017
v::alnum(' ')->assert('foo 123');
2118
// Validation passes successfully
2219

20+
v::alnum()->assert('foo 123');
21+
// → "foo 123" must contain only letters (a-z) and digits (0-9)
22+
2323
v::alnum()->assert('100%');
2424
// → "100%" must contain only letters (a-z) and digits (0-9)
2525

docs/validators/Alpha.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ Validates whether the input contains only alphabetic characters. This is similar
1212
to [Alnum](Alnum.md), but it does not allow numbers.
1313

1414
```php
15-
v::alpha()->assert('some name');
16-
// → "some name" must contain only letters (a-z)
17-
1815
v::alpha(' ')->assert('some name');
1916
// Validation passes successfully
2017

18+
v::alpha()->assert('some name');
19+
// → "some name" must contain only letters (a-z)
20+
2121
v::alpha()->assert('Cedric-Fabian');
2222
// → "Cedric-Fabian" must contain only letters (a-z)
2323

docs/validators/AlwaysInvalid.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ SPDX-License-Identifier: MIT
1010
Validates any input as invalid.
1111

1212
```php
13+
v::not(v::alwaysInvalid())->assert('whatever');
14+
// Validation passes successfully
15+
1316
v::alwaysInvalid()->assert('whatever');
1417
// → "whatever" must be valid
1518
```

docs/validators/BetweenExclusive.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ SPDX-License-Identifier: MIT
1010
Validates whether the input is between two other values, exclusively.
1111

1212
```php
13-
v::betweenExclusive(10, 20)->assert(10);
14-
// → 10 must be greater than 10 and less than 20
15-
1613
v::betweenExclusive('a', 'e')->assert('c');
1714
// Validation passes successfully
1815

16+
v::betweenExclusive(10, 20)->assert(10);
17+
// → 10 must be greater than 10 and less than 20
18+
1919
v::betweenExclusive(new DateTime('yesterday'), new DateTime('tomorrow'))->assert(new DateTime('today'));
2020
// Validation passes successfully
2121

docs/validators/Call.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ SPDX-License-Identifier: MIT
99

1010
Validates the return of a [callable][] for a given input.
1111

12+
```php
13+
v::call(str_split(...), v::arrayType()->lengthEquals(5))->assert('world');
14+
// Validation passes successfully
15+
```
16+
1217
Consider the following variable:
1318

1419
```php

docs/validators/Callback.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ SPDX-License-Identifier: MIT
1111
Validates the input using the return of a given callable.
1212

1313
```php
14-
v::callback(
15-
fn (int $input): bool => $input + ($input / 2) == 15,
16-
)->assert(10);
14+
v::callback(fn (int $input): bool => $input % 5 === 0,)->assert(10);
1715
// Validation passes successfully
1816
```
1917

docs/validators/Charset.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ SPDX-License-Identifier: MIT
1111
Validates if a string is in a specific charset.
1212

1313
```php
14-
v::charset('ASCII')->assert('açúcar');
15-
// → "açúcar" must only contain characters from the `["ASCII"]` charset
16-
1714
v::charset('ASCII')->assert('sugar');
1815
// Validation passes successfully
1916

17+
v::charset('ASCII')->assert('açúcar');
18+
// → "açúcar" must only contain characters from the `["ASCII"]` charset
19+
2020
v::charset('ISO-8859-1', 'EUC-JP')->assert('日本国');
2121
// Validation passes successfully
2222
```

docs/validators/Circuit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ SPDX-License-Identifier: MIT
1010

1111
Validates the input against a series of validators until the first fails.
1212

13+
```php
14+
v::circuit(v::intVal(), v::floatVal())->assert(15);
15+
// Validation passes successfully
16+
```
17+
1318
This validator can be handy for getting the least error messages possible from a chain.
1419

1520
This validator can be helpful in combinations with [Lazy](Lazy.md). An excellent example is when you want to validate a

docs/validators/Cnpj.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ SPDX-License-Identifier: MIT
1010
Validates if the input is a Brazilian National Registry of Legal Entities (CNPJ) number.
1111
Ignores non-digit chars, so use `->digit()` if needed.
1212

13+
```php
14+
v::cnpj()->assert('00394460005887');
15+
// Validation passes successfully
16+
```
17+
1318
## Templates
1419

1520
### `Cnpj::TEMPLATE_STANDARD`

0 commit comments

Comments
 (0)