Skip to content

[PropertyInfo] Invalid type extracted when property defined in trait #28732

Closed
@ychanan

Description

@ychanan
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version v4.1.3

Description
When using the PhpDocExtractor to extract information about a property, if that property is defined within a trait, the resulting type does not take into consideration the use statements in that trait.

How to reproduce

# src/App/Entity/TestEntity.php

namespace App\Entity;

class TestEntity
{
    use TestTrait;
}
# src/App/Entity/TestTrait.php

namespace App\Entity;

use Doctrine\Common\Collections\Collection;

trait TestTrait
{
    /**
     * @var Collection
     */
    protected $myCollection;
}
$phpDocExtractor = new PhpDocExtractor();
$types = $phpDocExtractor->getTypes(TestEntity::class, 'myCollection');
echo $types[0]->getClassName();

Got: App\Entity\Collection
Expected: Doctrine\Common\Collections\Collection

Additional information

  • Tested with other classes as well, not just Doctrine Collection, same result.
  • If we add use Doctrine\Common\Collections\Collection; to the TestEntity class, then it works as expected.
  • If we add the fully-qualified class name (\Doctrine\Common\Collections\Collection) to the @var tag on the $myCollection property, then it also works as expected.

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