Skip to content

How to read custom class annotation in extension #4403

Discussion options

You must be logged in to vote

I'd do something like this:

$classNames = TypeUtils::getDirectClassNames($calledOnType);
foreach ($classNames as $className) {
    if (!$this->reflectionProvider->hasClass($className)) { // inject "PHPStan\Reflection\ReflectionProvider" in the constructor
        continue;
    }

    $classReflection = $this->reflectionProvider->getClass($className);
    $phpDoc = $classReflection->getResolvedPhpDoc();
    if ($phpDoc === null) {
        continue;
    }
    // there's `$phpDoc->getPhpDocNodes()`, an array of PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode objects
    // it's an array because of complexities related to implicit phpDoc inheritance from parent methods etc.
    // you should be ab…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@MartinMystikJonas
Comment options

Answer selected by ondrejmirtes
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Support
Labels
None yet
2 participants