How to resolve FQCN of a PhpDoc which uses alias? #10765
-
Hello, in a custom rule, I'm reading phpdoc from a property like this: $tokens = new TokenIterator($this->phpDocLexer->tokenize($docComment->getText()));
$phpDocNodes = $this->phpDocParser->parse($tokens); but my phpdoc uses some aliases: use Some\Namespace as SomeNamespaceAlias;
class Dummy
{
/** @var list<SomeNamespaceAlias\SomeClass> */
public array $someClasses = [];
} Then my docnode looks like this:
how can I resolve the FQCN? I also tried to use the following $this->fileTypeMapper->getResolvedPhpDoc(fileName: null, className: $class, traitName: null, functionName: null, docComment: $docComment->getText()); but it seems the full type is not resolved either... bonus question: is there some documentation which I can refer to for this kind of "complex" case? thanks for your answer! 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I'm happy to help you, I just need more context and information. What are you trying to achieve with your custom rule? |
Beta Was this translation helpful? Give feedback.
-
Hi, thanks for your answer. I want to enforce cohesion between the phpdoc and a custom doctrine type, which helps us to store value objects as json in the database: use Fully\Qualified\Class\Name as SomeNamespaceAlias;
#[ORM\Entity]
class SomeEntity
{
/** @var list<SomeNamespaceAlias\SomeClass> */ // <--- I want this...
#[ORM\Column('list<Fully\Qualified\Class\Name\SomeClass>')] // <--- ...to be coherent with this
public array $someClasses = [];
} |
Beta Was this translation helpful? Give feedback.
You can read that from PropertyReflection:
You don't need to parse PHPDocs manually at all.