We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Given:
use Psl\Type; $shape = Type\shape([ 'name' => Type\string(), 'articles' => Type\vec(Type\shape([ 'title' => Type\string(), 'content' => Type\string(), 'likes' => Type\int(), 'comments' => Type\optional(Type\vec(Type\shape([ 'user' => Type\string(), 'comment' => Type\string() ]))), ])) ]); try { $shape->coerce([ 'name' => 'ok', 'articles' => [ [ 'title' => 'ok', 'content' => new stdClass, ] ] ]); } catch (Type\Exception\CoercionException $e) { echo $e->getMessage().PHP_EOL; var_dump($e->getTypeTrace()->getFrames()); }
This results in:
Could not coerce "stdClass" to type "string". array(3) { [0] => string(20) "array{'articles': _}" [1] => string(120) "vec<array{'title': string, 'content': string, 'likes': int, 'comments'?: vec<array{'user': string, 'comment': string}>}>" [2] => string(19) "array{'content': _}" }
Both the path and frames are rather confusing and it is unclear what failed exactly without processing this information.
Suggestion:
Keep track of an additional path on the TypeTraceso that we can build errors like:
path
TypeTrace
Could not coerce "stdClass" to type "string" at path articles.0.content
The path can contain a list of strings to identify the path - which will be set for shape and vec-like types:
prop
0
key
The list of paths will be .-separated
.
❗Consider the performance/memory impact, because PSL assertions are already quite runtime-heavy
The text was updated successfully, but these errors were encountered:
azjezz
Successfully merging a pull request may close this issue.
Given:
This results in:
Both the path and frames are rather confusing and it is unclear what failed exactly without processing this information.
Suggestion:
Keep track of an additional
path
on theTypeTrace
so that we can build errors like:The
path
can contain a list of strings to identify the path - which will be set for shape and vec-like types:prop
0
key
The list of paths will be
.
-separated❗Consider the performance/memory impact, because PSL assertions are already quite runtime-heavy
The text was updated successfully, but these errors were encountered: