Skip to content

Commit add90b7

Browse files
committed
Improve Documentation
- Added `composer docs-serve` to preview documentation locally. - Improved `ValidatorRelatedLinter` to not include invalid related entries. - Updated `CONTRIBUTING.md`
1 parent b352f17 commit add90b7

25 files changed

+40
-84
lines changed

CONTRIBUTING.md

Lines changed: 34 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,8 @@ SPDX-License-Identifier: MIT
88
Contributions to Respect\Validation are always welcome. You make our lives
99
easier by sending us your contributions through [pull requests][].
1010

11-
Pull requests for bug fixes must be based on the oldest stable version's branch
12-
whereas pull requests for new features must be based on the `master` branch.
13-
1411
Due to time constraints, we are not always able to respond as quickly as we
15-
would like. Please do not take delays personal and feel free to remind us here,
16-
on IRC, or on Gitter if you feel that we forgot to respond.
17-
18-
Please see the [project documentation][] before proceeding. You should also know
19-
about [PHP-FIG][]'s standards and basic unit testing, but we're sure you can
20-
learn that just by looking at other validators. Pick the simple ones like `ArrayType`
21-
to begin.
12+
would like. Please do not take delays personally.
2213

2314
Before writing anything, feature or bug fix:
2415

@@ -28,7 +19,7 @@ Before writing anything, feature or bug fix:
2819
to work on that;
2920
- If there is, create a comment to notify everybody that you're going to
3021
work on that.
31-
- Make sure that what you need is not done yet
22+
- Make sure that what you need is not done yet.
3223

3324
## Adding a new validator
3425

@@ -40,10 +31,8 @@ A common validator on Respect\Validation is composed of three classes:
4031
The classes are pretty straightforward. In the sample below, we're going to
4132
create a validator that validates if a string is equal to "Hello World".
4233

43-
- Classes should be `final` unless they are used in a different scope;
44-
- Properties should be `private` unless they are used in a different scope;
45-
- Classes should use strict typing;
46-
- Some docblocks are required.
34+
- Validator classes should be `final` whenever possible.
35+
- Properties should be `private` and `readonly` whenever possible.
4736

4837
### Creating the validator
4938

@@ -75,7 +64,7 @@ use Respect\Validation\Validators\Core\Simple;
7564
'{{subject}} must be a Hello World',
7665
'{{subject}} must not be a Hello World',
7766
)]
78-
final class HelloWorld extends Simple
67+
final readonly class HelloWorld extends Simple
7968
{
8069
protected function isValid(mixed $input): bool
8170
{
@@ -90,10 +79,8 @@ Finally, we need to test if everything is running smooth. We have `RuleTestCase`
9079
that allows us to make easier to test validators, but you fell free to use the
9180
`PHPUnit\Framework\TestCase` if you want or you need it's necessary.
9281

93-
The `RuleTestCase` extends PHPUnit's `PHPUnit\Framework\TestCase` class, so you
94-
are able to use any methods of it. By extending `RuleTestCase` you should
95-
implement two methods that should return a [data provider][] with the validator as
96-
first item of the arrays:
82+
The `RuleTestCase` extends PHPUnit's `PHPUnit\Framework\TestCase` class with
83+
conventional [data provider][] methods:
9784

9885
- `providerForValidInput`: Will test when `validate()` should return `true`
9986
- `providerForInvalidInput`: Will test when `validate()` should return `false`
@@ -142,60 +129,49 @@ for it other than what is covered by `RuleTestCase`.
142129

143130
### Helping us a little bit more
144131

145-
Your validator will be accepted only with these 3 files (validator and unit test),
146-
but if you really want to help us, you can follow the example of [ArrayType][] by:
147-
148-
- Adding your new validator on the `Validator`'s class docblock;
149-
- Writing a documentation for your new validator;
150-
- Creating integration tests with PHPT.
132+
You should include documentation to your new validator. A minimal document
133+
is acceptable. You can use `bin/console lint:docs` to help you ensure that
134+
document follows our conventions. `bin/console lint:docs --fix` will even
135+
fix some common mistakes automatically.
151136

152-
As we already said, none of them are required but you will help us a lot.
137+
Additionally, consider adding a feature test to `tests/feature`. Those help
138+
us track common use cases and usage patterns.
153139

154140
## Documentation
155141

156142
Our docs at https://respect-validation.readthedocs.io are generated from our
157143
Markdown files. Add your brand new validator and it should be soon available.
158144

159-
## Running Tests
145+
You can preview how the docs will look like by running `composer docs-serve`.
160146

161-
After run `composer install` on the library's root directory you must run PHPUnit.
147+
## Running Checks
162148

163-
### Linux
149+
After run `composer install` on the library's root directory you must run
150+
`composer qa`.
164151

165-
You can test the project using the commands:
152+
This alias will run several checks, including unit tests, static analysis
153+
and more.
166154

167-
```sh
168-
$ vendor/bin/phpunit
169-
```
170-
171-
or
155+
Check out the `scripts` section on `composer.json` for more details on which
156+
checks are performed.
172157

173-
```sh
174-
$ composer phpunit
175-
```
158+
## Benchmarks
176159

177-
### Windows
160+
If you want to improve the project performance or make sure your change doesn't
161+
introduce a performance regression, you can use our standard benchmark suite
162+
at `tests/benchmark`.
178163

179-
You can test the project using the commands:
180-
181-
```sh
182-
> vendor\bin\phpunit
183-
```
184-
185-
or
186-
187-
```sh
188-
> composer phpunit
189-
```
164+
Typical workflow:
190165

191-
No test should fail.
166+
- (Optional) Write a new benchmark in `tests/benchmark`.
167+
- Run `vendor/bin/phpbench run --tag=before` before making a change.
168+
- Change the code as you like.
169+
- Run `vendor/bin/phpbench run --ref=before` to compare performance with the
170+
tagged run.
192171

193-
You can tweak the PHPUnit's settings by copying `phpunit.xml.dist` to `phpunit.xml`
194-
and changing it according to your needs.
172+
Check out the [phpbench documentation](https://phpbench.readthedocs.io/en/latest/index.html)
173+
for more information.
195174

196-
[ArrayType]: https://github.com/Respect/Validation/commit/f08a1fa
197-
[data provider]: https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.data-providers "PHPUnit Data Providers"
175+
[data provider]: https://docs.phpunit.de/en/12.5/writing-tests-for-phpunit.html#data-providers "PHPUnit Data Providers"
198176
[open an issue]: http://github.com/Respect/Validation/issues
199-
[PHP-FIG]: http://www.php-fig.org "PHP Framework Interop Group"
200-
[project documentation]: https://respect-validation.readthedocs.io/ "Respect\\Validation documentation"
201177
[pull requests]: http://help.github.com/pull-requests "GitHub pull requests"

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"bench-profile": "vendor/bin/phpbench xdebug:profile",
7878
"bench": "vendor/bin/phpbench run",
7979
"docs-fix": "bin/console lint:docs --fix",
80+
"docs-serve": "pip install -qr docs/requirements.txt && mkdocs serve",
8081
"docs": "bin/console lint:docs",
8182
"pest": "vendor/bin/pest --testsuite=feature --compact",
8283
"phpcs": "vendor/bin/phpcs",

docs/validators/Callback.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,3 @@ v::callback(fn (int $input): bool => $input % 5 === 0,)->assert(10);
4545
- [Call](Call.md)
4646
- [CallableType](CallableType.md)
4747
- [DateTime](DateTime.md)
48-
- [FilterVar](FilterVar.md)

docs/validators/Charset.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,3 @@ The array format is a logic OR, not AND.
5454

5555
- [Alnum](Alnum.md)
5656
- [Alpha](Alpha.md)
57-
- [PhpLabel](PhpLabel.md)

docs/validators/Directory.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,4 @@ v::directory()->assert(dir('/'));
6464
- [Readable](Readable.md)
6565
- [Size](Size.md)
6666
- [SymbolicLink](SymbolicLink.md)
67-
- [Uploaded](Uploaded.md)
6867
- [Writable](Writable.md)

docs/validators/Email.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,3 @@ v::email()->assert('alganet@gmail.com');
4646
- [Json](Json.md)
4747
- [Phone](Phone.md)
4848
- [Url](Url.md)
49-
- [VideoUrl](VideoUrl.md)

docs/validators/Executable.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,4 @@ v::executable()->assert('/path/to/file');
5353
- [Readable](Readable.md)
5454
- [Size](Size.md)
5555
- [SymbolicLink](SymbolicLink.md)
56-
- [Uploaded](Uploaded.md)
5756
- [Writable](Writable.md)

docs/validators/Exists.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,4 @@ v::exists()->assert(new SplFileInfo('/path/to/file.txt'));
6060
- [Readable](Readable.md)
6161
- [Size](Size.md)
6262
- [SymbolicLink](SymbolicLink.md)
63-
- [Uploaded](Uploaded.md)
6463
- [Writable](Writable.md)

docs/validators/Extension.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,4 @@ This validator is case-sensitive.
5353
- [Readable](Readable.md)
5454
- [Size](Size.md)
5555
- [SymbolicLink](SymbolicLink.md)
56-
- [Uploaded](Uploaded.md)
5756
- [Writable](Writable.md)

docs/validators/Factor.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,3 @@ v::factor(4)->assert(3);
5454
- [Finite](Finite.md)
5555
- [Infinite](Infinite.md)
5656
- [NumericVal](NumericVal.md)
57-
- [PerfectSquare](PerfectSquare.md)
58-
- [PrimeNumber](PrimeNumber.md)

0 commit comments

Comments
 (0)