Skip to content

Roadmap to 3.0 #1447

@henriquemoody

Description

@henriquemoody

To-dos

I'm almost there, and there are some awesome improvements coming!

Core

  • Improve array messages
  • Create Validator::validate() that returns an object with errors
  • ? Rename Result->isValid to Result->hasPassed
  • Create transformer to deal with composite rules with a single argument
  • Make Simple::isValid public
  • Use paths to identify when a rule fails
  • Create {{placeholder|quote}}
  • Create custom Stringifier, removing CallableStringifier
  • Replace setName() with Named rule
  • Get ignored paths for ValidationException from ValidatorDefaults
  • Replace setTemplate() with Templated rule
  • Create class alias for old abstract classes
  • Rename mode "negative" to "inverted"
  • Add second parameter to Validator::assert()
  • Create "key" prefix
  • Create "length" prefix
  • Create "max" prefix
  • Create "min" prefix
  • Create "nullOr" prefix
  • Create "property" prefix
  • Create "undefOr" prefix
  • Make ComponentException extend LogicException
  • Make getMessages() return __self__
  • Make setName() update names, but not IDs
  • Prefix ids when working with sibling results
  • Update validation engine (todo: split into different tasks)
  • Use PHP Attributes to define templates

Rules

  • Create Masked rule -- which allows masking the input
  • Promote Reducer to an actual rule
  • Enable Attributes to deal with inheritance
  • Allow to use certain rules as class attributes
  • Rename "Consecutive" to something shorter
  • Only create Max with subsequents when possible
  • Only create Min with subsequents when possible
  • Only create Length with subsequents when possible
  • Add support to PHP 8.4
  • Update DateTimeDiff to generate results with subsequents
  • Tentatively created a result with subsequents in UndefOr and NullOr
  • Refactor KeySet rule
  • Create DateDiff rule
  • Delete MinAge, MaxAge, and Age rules
  • Rename NotOptional to NotUndef
  • Create BetweenExclusive rule
  • Create Consecutive rule
  • Create LazySequence rule
  • Create a new Max rule
  • Create a new Min rule
  • Create aliases for deprecated/removed rules
  • Delete KeyValue rule
  • Do not use When as a sibling
  • Refactor Length rule
  • Rename Nullable to NullOr
  • Rename Optional to UndefOr
  • Rename Max rule to LessThanOrEqual
  • Rename Min rule to GreaterThanOrEqual
  • Rename the "Attribute" rule to "Property"
  • Split the Key rule into Key, KeyExists, and KeyOptional
  • Split the Property rule into Property, PropertyExists, and PropertyOptional

Other

  • Make documentation up to date with the changes
  • Write a blog post with the latest changes
  • Improve documentation for rules that are prefixes
  • Release version 2.4 with deprecations
  • Fix broken documentation links
  • Rename branch master to main

Nice to have

- [ ] More integration tests for `oneOf`, `allOf` and `each` validator messages.
- [ ] Create `All` rule (similar to `Each` but creates results with subsequents)
- [ ] Create `DateTimeParseable` or (`DateTimeLenient`) rule
- [ ] Increase code coverage to 98%
- [ ] Share credentials for @TheRespectPanda with @alganet
- [ ] Extra documentation for most common support issues
  - [ ] Message translation approaches
  - [ ] Navigating the messages tree manually
  - [ ] Using validators with custom names 
  - [ ] Expressing boolean algebra

Update validation engine

Here are some "problems" I see with the current engine

  • Allowing each rule to execute assert() and check() means duplication in some cases.
  • Because we use exceptions to assert/check, we can only invert a validation (with Not) if there are errors. That means that we have limited granularity control.
  • There is a lot of logic in the exceptions. That means that even after an exception is thrown, something could still happen. We're stable on that front, but I want to simplify them. Besides, debugging exception code is painful because the stack track stops once the exception constructor is created.

On version 3.0, this won't be possible anymore:

$email = new Email():
$email->assert($input);

Instead, you would need to do that:

$validator = new Validator(new Email());
$validator->assert($input);

However, because assert() will be available only on Validator, you could do things like that:

// Passing the template as a string
v::email()->assert($input, 'Uff... {{input}} should have been an email');

// Passing an array of templates
v::intValue()->positive()->lessThan(5)->assert($input, [
    'intValue' => 'Area must be an integer',
    'positive' => 'Area must be a positive number',
    'lessThan' => 'Area cannot be bigger than m2',
]);

// Passing a custom exception
v::email()->assert($input, new DomainException('Customers must have valid emails'));

// Passing a custom callable
v::email()->assert($input, fn($exception) => new DomainException('Something failed: ' . $exception->getMessage());

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions