Skip to content

TypeResolver resolve ?string|null|?boolean|?int as Nullable instead of Compound #69

@steevanb

Description

@steevanb

Hi,

When i want to resolve a variable type, there is a little bug when it begin with ?: it should return a Compound object, but it return a Nullable object, with Compound as realType. As you can see in example below, in ?string|null|?boolean , ?boolean is well parsed, cause it's not the first one.

$typeResolver = new TypeResolver();
print_r($typeResolver->resolve('?string|null|?boolean'));
phpDocumentor\Reflection\Types\Nullable Object
(
    [realType:phpDocumentor\Reflection\Types\Nullable:private] => phpDocumentor\Reflection\Types\Compound Object
        (
            [types:phpDocumentor\Reflection\Types\Compound:private] => Array
                (
                    [0] => phpDocumentor\Reflection\Types\String_ Object
                        (
                        )
                    [1] => phpDocumentor\Reflection\Types\Null_ Object
                        (
                        )
                    [2] => phpDocumentor\Reflection\Types\Nullable Object
                        (
                            [realType:phpDocumentor\Reflection\Types\Nullable:private] => phpDocumentor\Reflection\Types\Boolean Object
                                (
                                )
                        )
                )
        )
)

Another example, that works well, without ? as first character:

$typeResolver = new TypeResolver();
print_r($typeResolver->resolve('string|null|?boolean'));
phpDocumentor\Reflection\Types\Compound Object
(
    [types:phpDocumentor\Reflection\Types\Compound:private] => Array
        (
            [0] => phpDocumentor\Reflection\Types\String_ Object
                (
                )
            [1] => phpDocumentor\Reflection\Types\Null_ Object
                (
                )
            [2] => phpDocumentor\Reflection\Types\Nullable Object
                (
                    [realType:phpDocumentor\Reflection\Types\Nullable:private] => phpDocumentor\Reflection\Types\Boolean Object
                        (
                        )
                )
        )
)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions