Skip to content

[PropertyInfo] PhpStanExtractor with @phpstan-type is treated as a class, which not exists #17176

@michaljusiega

Description

@michaljusiega

Description

Hi,
I'm facing weird issue in SF 7.2:

The following code:

<?php

use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor;
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;

/** @phpstan-type AspectRatio 1.0|1.1|1.2|1.3|1.4|1.5|1.6|1.7|1.8|1.9|2.0 */
class Test1234
{
    /** @param AspectRatio|null $aspectRatio */
    public function __construct(public float|null $aspectRatio)
    {
    }
}

$propertyInfo = new PropertyInfoExtractor(
    listExtractors: [],
    typeExtractors: [new PhpStanExtractor(), new ReflectionExtractor()],
    descriptionExtractors: [],
    accessExtractors: [],
    initializableExtractors: []
);

$types = $propertyInfo->getTypes(Test1234::class, 'aspectRatio');

dump($types);

Resulted in this output:

 array:1 [▼
  0 => Symfony\Component\PropertyInfo\Type {#42 ▼
    -collectionKeyType: []
    -collectionValueType: []
    -builtinType: "object"
    -nullable: true
    -class: "AspectRatio"
    -collection: false
  }
]

But I expected this output instead:

 array:1 [▼
  0 => Symfony\Component\PropertyInfo\Type {#23 ▼
    -collectionKeyType: []
    -collectionValueType: []
    -builtinType: "float"
    -nullable: true
    -class: null
    -collection: false
  }
]

Exactly the same result is expected when we set PropertyInfoExtrator to typeExtractors: [new ReflectionExtractor()].

I don't know how to fix this, but I guess this bug is maybe related with phpstan/phpdoc-parser by symfony/symfony#58800

Thanks for help!

PHP Version

PHP 8.4

Operating System

Ubuntu

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