Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] translation:extract The annotation "@suppress" ... was never imported. #420

Open
Aerendir opened this issue Sep 3, 2020 · 0 comments

Comments

@Aerendir
Copy link

Aerendir commented Sep 3, 2020

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?

@Aerendir Aerendir changed the title The annotation "@suppress" ... was never imported. [BUG] translation:extract The annotation "@suppress" ... was never imported. Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant