api-platform / api-platform

🕸️ Create REST and GraphQL APIs, scaffold Jamstack webapps, stream changes in real-time.
https://api-platform.com
MIT License
8.54k stars 959 forks source link

The FQN of a variables inside a trait inside an entity is not properly calculated #1568

Open davidrojo opened 4 years ago

davidrojo commented 4 years ago

API Platform version(s) affected: 2.5.6

Description
When having a trait inside an entity, if you use @var File then ApiPlatform tries to load the entity from App\Entities\File instead of the FQN defined in the use statement.

How to reproduce
With the sample code of Api/platform (https://api-platform.com/docs/distribution/#installing-the-framework)

Create a file src/Entity/FileTrait.php

<?php
namespace App\Entity;

use Symfony\Component\HttpFoundation\File\File;

trait FileTrait
{
    /** @var File */
    public $file;
}

Modify src/Entity/Greetings.php and add:

class Greetings
{
   ...
   use FileTrait;
   ...
}

When doing this accessing localhost:8443 you will receive the error "Class App\Entity\File does not exist"

If you change in "FileTrait" the var with the FQN of the File class, it works fine

/** @var \Symfony\Component\HttpFoundation\File\File */
public $file;
soyuka commented 4 years ago

related to https://github.com/api-platform/core/issues/3349 AFAIU