Remove the setTemplate() method from Validator

The `setTemplate()` method can be confusing, as it can be tricky for
someone to determine which chain is being templated. Using the
`Templated` rule makes this much more explicit and adds a little bit of
verbosity. For users, this will be a significant change, but there are
easy ways to update this code in their projects, so I’m not overly
concerned about it.

Another benefit of this change is that it makes the `Validator` much
simpler, as it no longer needs to track the template. This change also
makes the `Reducer` simpler, for similar reasons to the `Validator`.
However, because the `Validator` is simpler, we can remove the code that
the `Reducer` had to meet the specific needs of the `Validator`.
This commit is contained in:
Henrique Moody 2026-01-02 12:50:33 +01:00
commit d9380588e7
No known key found for this signature in database
GPG key ID: 221E9281655813A6
14 changed files with 63 additions and 147 deletions

View file

@ -8,7 +8,7 @@
declare(strict_types=1);
test('Scenario #1', catchFullMessage(
fn() => v::callback('is_string')->between(1, 2)->setTemplate('{{subject}} is not tasty')->assert('something'),
fn() => v::templated(v::callback('is_string')->between(1, 2), '{{subject}} is not tasty')->assert('something'),
fn(string $fullMessage) => expect($fullMessage)->toBe(<<<'FULL_MESSAGE'
- "something" is not tasty
- "something" must be between 1 and 2