Skip to content

Extend Reflection to expose import statements #14085

Closed as not planned
Closed as not planned
@Korbeil

Description

@Korbeil

Hey,

Nowadays there is a limit when trying to resolve a type from a phpDoc in PHP, you'll need to get a "context" for the file where the type as been written. Let's make an exemple with a use import combined with the as keyword:

use App\Command\Foo as Command;

/** @var Command */
$command = my_command();

Another example, you have two classes with the same name but in different namespaces: App\Foo and App\Command\Foo

use App\Command\Foo;

/** @var Foo */
$command = my_command();

Considering both theses example, we require to parse the whole file to check for use import statements so we can have context for the phpDoc types within this file.

To solve this issue with Reflection, it would require:

  • ReflectionFile an object that describe the content of a file: a list of ReflectionImport and any other stuff within that file (ReflectionClass ...)
  • ReflectionImport an object that describe a use statement with a linked ReflectionClass and a local alias when required

I chosed to not use the keyword use within Reflection here because I think it's too much missleading and import has more meaning in that context.

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