fix: Undefined array input type#819
Conversation
|
@michael-georgiadis I'm not quite sure I understand the issue here. Where are things breaking? |
|
@oojacoboo So, up until now the library handled the undefined compounds on the non-doc-block based type hints. An But for this case /** @param list<int> $array */
private array|Undefined|null $array;if the code block below does not exist: if ($innerType instanceof Compound && UndefinedTypeMapper::containsUndefined($innerType)) {
$innerType = NullableTypeMapperAdapter::getNonNullableType(
UndefinedTypeMapper::replaceUndefinedWith($innerType),
) ?? $innerType;
} The type coming in in this if statement if (
$innerType instanceof Array_
|| $innerType instanceof Iterable_
|| $innerType instanceof Mixed_
|| $innerType instanceof Callable_
|| ($innerType instanceof Object_
&& $docBlockType instanceof Collection
&& (string) $innerType->getFqsen() === (string) $docBlockType->getFqsen()
)
)was a So the fix here is basically unwrapping the compound with previously written code and making sure that the innerType is handled as an Array instead and prints the type correctly. Scalars also work by passing the else statement, but there are no conflicting docblocks so they survive |
|
This is not me being passive aggressive btw, but you can checkout the branch and try the integration tests with the fixtures but reverting the actual code-change and you will see that it blows up |
Description
Optional-via-
Undefinedworks for scalars but explodes on lists:Fix: drop Undefined and take the non-null core before the container check, reusing existing helpers (UndefinedTypeMapper + a now-public static getNonNullableType).
Covers array/list. Native iterable isn't handled (PHP expands it to array|Traversable) and since it's rare for an input, I left it alone