Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[PropertyInfo] Nullable array value types and multiple key/value types not returned with PhpDocExtractor #49555

Closed
@MudrakIvan

Description

@MudrakIvan

Symfony version(s) affected

5.3 - 6.3

Description

PhpDocExtractor is not able to return nullable array value types and throws exception with invalid class name/invalid type. Example phpDoc:

/**
 * @var array<?\DateTime>
 */
public array $arrayOfNullableDateTimes;

/**
 * @var array<\DateTime|null>
 */
public array $arrayOfNullableDateTimes2;

PhpDocExtractor is also unable to return mutliple value/key data types in array/collection. Example phpDoc:

/**
 * @var array<int|string>
 */
public $arrayOfMultipleValueTypes;

How to reproduce

To reproduce use PropertyInfo component with PhpDocExtractor. Error will be shown, when extracting type from property with nullable array value type. Also when extracting type from property with multiple array key/value type, empty arrry will be returned.

Possible Solution

To fix the problem, use getType instead of createType in PhpDocTypeHelper. To add multiple array value/key types return all extracted types (remove count check). I will also make a PR with solution.

Additional Context

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