jasny / jasny/validation-result

Add support for error types

Open
#1 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
4
Forks
3
PR merge metrics
No merged PRs in 30d

Description

Add the possibility to add a type to an error. We might create an class for a validation error with a `__toString()` method. The class would have a `setType()` and `getType()` method.

The `ValidationResult::getErrors()` method should take a `$type` argument to only get errors of a specific type.

``` php
$validation = new ValidationResult();
$validation->addError("Failed parsing hello %s", "world")->setType('syntax');
```

Example use case:

``` php
$validation = $foo->validation();

if ($validation->failed()) {
if ($validation->getErrors('unique')) {
return $this->conflict($validation->getErrors('unique'));
} else {
return $this->badRequest($validation->getErrors());
}
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by inspecting the ValidationResult class, especially addError() and getErrors(), and look for existing validation-result tests. Determine how errors are represented and how a typed error should be stringified. Done means errors can carry a type and getErrors($type) filters by it without breaking untyped retrieval.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.