phpDocumentor/TypeResolver

Support for list<Foo> type

enumag opened this issue · 1 comments

I noticed that TypeResolver currently doesn't support the list type which is generally used as subtype of array<int, Foo>, indicating it's an array that PHP's array_is_list() function would return true.

It's described in more detail in Psalm's documentation for instance: https://psalm.dev/docs/annotating_code/type_syntax/array_types/#lists

From browsing the code it seems this would need to be handled in TypeResolver::resolveCollection().

What do you think about supporting this in this library?

Thanks for reporting this.

I think our generics support can be improved. I'm not sure yet how to do this, but we are definitely open for pr's to help us move forward. When I quickly scan the way psalm treads the list type I think this could be a Pseudo type like we have for strings. Maybe we should remove the check in

if (
!$isArray && !$isIterable
&& (!$classType instanceof Object_ || $classType->getFqsen() === null)
) {
throw new RuntimeException(
$classType . ' is not a collection'
);
}

To have better support for all type definitions containing <> .

Please let me know when you want to help us to improve this library, and build support for the list type. I'm available to help you when needed.