respect-validation/docs
Henrique Moody b5ad7aa47a
Make Validator immutable
Mutable objects can be challenging to work with in larger codebases
because different parts of a system may modify the same instance, making
it difficult to trace where and when changes occurred. This becomes
especially problematic when debugging unexpected behaviour.

By making `Validator` immutable, we ensure that adding rules via
`with()` returns a new instance rather than mutating the original, and
we use the `with()` method inside `__call()`, making every call to a
rule into a clone of the current `Validator`.

This provides several benefits:

1. Predictability: A `Validator` instance will always behave the same
   way throughout its lifetime, regardless of what other parts of the
   codebase do.

2. Safe dependency injection: Users can now confidently inject a base
   `Validator` from a DI container, knowing that any modifications made
   elsewhere will not affect their instance.

3. Easier debugging: Since validators cannot be mutated after creation,
   there's no need to track down where an unexpected rule was added.

4. Reusability: Users can create an initial `Validator` with some base
   rules and reuse it by just adding new rules to the chain without
   affecting the base `Validator`.
2026-01-02 15:45:23 +01:00
..
rules Make Validator immutable 2026-01-02 15:45:23 +01:00
01-installation.md Bump PHP support from 8.1 to 8.5 2025-12-18 19:03:38 +01:00
02-feature-guide.md Remove the setName() method from Validator 2026-01-02 15:45:23 +01:00
03-handling-exceptions.md Replace placeholder "name" with "subject" 2025-12-26 21:30:01 +01:00
04-message-translation.md Reformat documentation files 2025-12-27 17:03:25 +01:00
05-message-placeholder-conversion.md Replace placeholder "name" with "subject" 2025-12-26 21:30:01 +01:00
06-concrete-api.md Make Validator immutable 2026-01-02 15:45:23 +01:00
07-custom-rules.md Replace placeholder "name" with "subject" 2025-12-26 21:30:01 +01:00
08-comparable-values.md Reformat documentation files 2025-12-27 17:03:25 +01:00
09-list-of-rules-by-category.md Refactor the NotEmpty rule 2025-12-29 12:48:35 +01:00
10-license.md Improve the "Feature Guide" documentation 2024-12-05 00:21:34 +01:00
comparing-empty-values.md Refactor the NotEmpty rule 2025-12-29 12:48:35 +01:00
index.md Improve the "Feature Guide" documentation 2024-12-05 00:21:34 +01:00