Skip to content

Expand TypeInfo component to support advanced scalar types #59733

Closed as not planned
@zmitic

Description

@zmitic

Description

For a method like this:

/**
 * @param non-empty-string $name
 * @param int<0,100> $percent
 */
private function test($name, $percent): void
{
}

TypeResolver::resolve returns BuiltinType(string) and BuiltinType(int), without extra information. It would be really nice if we could read more of them, at least these 2 as they are most useful.


If you are interested in the use-case, I can provide an example. But in short: it is about static analysis and forms when we must use empty_data closure. When it fails, then #[Assert] attributes will not be read and user will never get any validation errors.

I already made an extension that solves this problem for builtin types (by using reflection and constraints normalizer), but these advanced one are tricky. I could have used phpstan/phpdoc-parser, but TypeInfo component already supports it so it would be nice to re-use it.

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions