Skip to content

Commit 7a1aa61

Browse files
committed
Add GitHub action to check outdated templates
We don't often change the tempaltes of validators, but when we do it's extremely important that the documentation of the validators match the exact template the validator has. This commit will create a console command to the GitHub workflow that will ensure that the documentation of validators are always aligned with the templates they have.
1 parent 47b80f8 commit 7a1aa61

14 files changed

Lines changed: 231 additions & 33 deletions

File tree

.github/workflows/continuous-integration-docs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@ jobs:
3535
- name: Validator headers
3636
run: bin/console docs:validators:headers
3737

38+
- name: Validator templates
39+
run: bin/console docs:validators:templates
40+
3841
- name: Related validators
3942
run: bin/console docs:validators:related

bin/console

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use Respect\Dev\Commands\CreateMixinCommand;
1414
use Respect\Dev\Commands\DocsValidatorsHeadersCommand;
1515
use Respect\Dev\Commands\DocsValidatorsListCommand;
1616
use Respect\Dev\Commands\DocsValidatorsRelatedCommand;
17+
use Respect\Dev\Commands\DocsValidatorsTemplatesCommand;
1718
use Respect\Dev\Commands\UpdateDomainSuffixesCommand;
1819
use Respect\Dev\Commands\UpdateDomainToplevelCommand;
1920
use Respect\Dev\Commands\UpdatePostalCodesCommand;
@@ -30,6 +31,7 @@ return (static function () {
3031
$application->addCommand(new DocsValidatorsHeadersCommand($differ));
3132
$application->addCommand(new DocsValidatorsListCommand($differ));
3233
$application->addCommand(new DocsValidatorsRelatedCommand($differ));
34+
$application->addCommand(new DocsValidatorsTemplatesCommand($differ));
3335
$application->addCommand(new UpdateDomainSuffixesCommand());
3436
$application->addCommand(new UpdateDomainToplevelCommand());
3537
$application->addCommand(new UpdatePostalCodesCommand());

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"docs:validators:headers": "bin/console docs:validators:headers",
7676
"docs:validators:index": "bin/console docs:validators:index",
7777
"docs:validators:related": "bin/console docs:validators:related",
78+
"docs:validators:templates": "bin/console docs:validators:templates",
7879
"docheader": "vendor/bin/docheader check library/ tests/",
7980
"phpcs": "vendor/bin/phpcs",
8081
"phpstan": "vendor/bin/phpstan analyze",
@@ -83,7 +84,8 @@
8384
"docs": [
8485
"@docs:validators:headers",
8586
"@docs:validators:index",
86-
"@docs:validators:related"
87+
"@docs:validators:related",
88+
"@docs:validators:templates"
8789
],
8890
"qa": [
8991
"@docheader",

docs/validators/All.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ This validator uses [Length](Length.md) with [GreaterThan][GreaterThan.md] inter
2424
| `default` | Every item in |
2525
| `inverted` | Every item in |
2626

27-
This template serve as message prefixes.:
27+
## Template as prefix
28+
29+
The template serves as a prefix to the template of the inner validator.
2830

2931
```php
3032
v::all(v::floatType())->assert([1.5, 2]);

docs/validators/DateTimeDiff.md

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ The supported types are:
3131

3232
## Templates
3333

34-
The first two templates serve as message suffixes:
35-
36-
```php
37-
v::dateTimeDiff('years', v::equals(2))->assert('1 year ago')
38-
// The number of years between now and 1 year ago must be equal to 2
39-
40-
v::not(v::dateTimeDiff('years', v::lessThan(8)))->assert('7 year ago')
41-
// The number of years between now and 7 year ago must not be less than 8
42-
```
43-
4434
### `DateTimeDiff::TEMPLATE_STANDARD`
4535

4636
Used when `$format` and `$now` are not defined.
@@ -54,10 +44,17 @@ Used when `$format` and `$now` are not defined.
5444

5545
Used when `$format` or `$now` are defined.
5646

57-
| Mode | Template |
58-
| ---------- | -------------------------------------------------------------- |
59-
| `default` | The number of {{type|trans}} between {{now|raw}} and |
60-
| `inverted` | The number of {{type|trans}} between {{now|raw}} and |
47+
| Mode | Template |
48+
| ---------- | ----------------------------------------------------- |
49+
| `default` | The number of {{type|trans}} between {{now}} and |
50+
| `inverted` | The number of {{type|trans}} between {{now}} and |
51+
52+
### `DateTimeDiff::TEMPLATE_NOT_A_DATE`
53+
54+
| Mode | Template |
55+
| ---------- | ------------------------------------------------------------------------------ |
56+
| `default` | For comparison with {{now|raw}}, {{subject}} must be a valid datetime |
57+
| `inverted` | For comparison with {{now|raw}}, {{subject}} must not be a valid datetime |
6158

6259
### `DateTimeDiff::TEMPLATE_WRONG_FORMAT`
6360

@@ -68,6 +65,18 @@ Used when the input cannot be parsed with the given format.
6865
| `default` | For comparison with {{now|raw}}, {{subject}} must be a valid datetime in the format {{sample|raw}} |
6966
| `inverted` | For comparison with {{now|raw}}, {{subject}} must not be a valid datetime in the format {{sample|raw}} |
7067

68+
## Template as prefix
69+
70+
The template serves as a prefix to the template of the inner validator.
71+
72+
```php
73+
v::dateTimeDiff('years', v::equals(2))->assert('1 year ago')
74+
// The number of years between now and 1 year ago must be equal to 2
75+
76+
v::not(v::dateTimeDiff('years', v::lessThan(8)))->assert('7 year ago')
77+
// The number of years between now and 7 year ago must not be less than 8
78+
```
79+
7180
## Template placeholders
7281

7382
| Placeholder | Description |

docs/validators/Instance.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Message template for this validator includes `{{instanceName}}`.
1717

1818
| Mode | Template |
1919
| ---------- | ----------------------------------------------------------- |
20-
| `default` | {{subject}} must be an instance of `{{class|raw}}` |
21-
| `inverted` | {{subject}} must not be an instance of `{{class|raw}}` |
20+
| `default` | {{subject}} must be an instance of {{class|quote}} |
21+
| `inverted` | {{subject}} must not be an instance of {{class|quote}} |
2222

2323
## Template placeholders
2424

docs/validators/Length.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@ Used when it's possible to get the length of the input.
3131
| `default` | The length of |
3232
| `inverted` | The length of |
3333

34-
This template serve as message prefixes.:
34+
### `Length::TEMPLATE_WRONG_TYPE`
35+
36+
| Mode | Template |
37+
| ---------- | ----------------------------------------------------- |
38+
| `default` | {{subject}} must be a countable value or a string |
39+
| `inverted` | {{subject}} must not be a countable value or a string |
40+
41+
## Template as prefix
42+
43+
The template serves as a prefix to the template of the inner validator.
3544

3645
```php
3746
v::length(v::equals(3))->assert('tulip');

docs/validators/Max.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ This validator uses [Length](Length.md) with [GreaterThan][GreaterThan.md] inter
2828
| `default` | The maximum of |
2929
| `inverted` | The maximum of |
3030

31+
## Template as prefix
32+
33+
The template serves as a prefix to the template of the inner validator.
34+
3135
## Template placeholders
3236

3337
| Placeholder | Description |

docs/validators/Min.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ This validator uses [Length](Length.md) with [GreaterThan][GreaterThan.md] inter
2828
| `default` | The minimum of |
2929
| `inverted` | The minimum of |
3030

31+
## Template as prefix
32+
33+
The template serves as a prefix to the template of the inner validator.
34+
3135
## Template placeholders
3236

3337
| Placeholder | Description |

docs/validators/NullOr.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ v::nullOrBetween(1, 3)->isValid(null); // true
3131
| `default` | or must be null |
3232
| `inverted` | and must not be null |
3333

34-
The templates from this validator serve as message suffixes:
34+
## Template as suffix
35+
36+
The template serves as a suffix to the template of the inner validator.
3537

3638
```php
3739
v::nullOr(v::alpha())->assert('has1number');

0 commit comments

Comments
 (0)