[BUG] `translation:extract` The annotation "@suppress" ... was never imported.
Aerendir opened this issue · comments
Complete error
[ERROR] /Users/Aerendir/Documents/JooServer/Lab/Bundles/bundle-users/src/Command/AbstractUserCommand.php
Line: 23
Message: Could not parse class "SerendipityHQ\Bundle\UsersBundle\Command" for annotations. [Semantical Error]
The annotation "@Suppress" in property SerendipityHQ\Bundle\UsersBundle\Command\AbstractUserCommand::$user
was never imported. Did you maybe forget to add a "use" statement for this annotation?
The error is cause by the use of annotation @suppress
that is used to suppress errors triggered by Phan (https://github.com/phan/phan/wiki/Annotating-Your-Source-Code#suppress).
The annotation hasn't to be imported.
Trying to debug the error, it seems it is triggered by Doctrine/Common/Annotations/DocParser
.
It is finally added as error in PHPTranslation in Translation\Extractor\Visitor\Php\Symfony\ValidationAnnotation
.
I've tried to add a simple condition like this:
try {
/** @var ClassMetadata $metadata */
$metadata = $this->metadataFactory->getMetadataFor($name);
} catch (AnnotationException $e) {
if (false === strpos($e->getMessage(), '"@suppress"')) {
$this->addError($node, sprintf('Could not parse class "%s" for annotations. %s', $this->namespace, $e->getMessage()));
return null;
}
}
But obviously it doesn't work, as the variable $metadata
is not created at all due to the exception:
In ValidationAnnotation.php line 86:
Notice: Undefined variable: metadata
So, it seems that is required to act on Doctrine DocParser
...
Then, on Doctrine side, the DocParser
has a useful option that permits to ignore some annotations: the ignored annotation don't throw any exception (Source: Doctrine/Common/Annotations/DocParser
).
The question is: how to configure DocParser
to ignore the @suppress
annotation?