Search code examples
phpapi-docphpstan

The annotation "@apiDefine" in class App\Controller\UserController was never imported


I am using both phpstan and apidoc, but i have an error on phpstan that i can't find a way to solve or ignore.


 Error message "Internal error: [Semantical Error] The annotation "@apiDefine" in class App\Controller\UserController was never imported. Did you maybe forget to add a "use" statement for this annotation?  
     Run PHPStan with --debug option and post the stack trace to:                                                                                                                                                        
     https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md" cannot be ignored, use excludePaths instead.

To my understanding, apidoc doesn't need any import, but when phpstan goes on my file it does not know this annotation so it triggers an error.

In my opinion the best solutions would be to ignore this kind of error, but it say:

cannot be ignored, use excludePaths instead.

But i would like to keep this file in the phpstan analyse.

How could i fix this error or ignore it ?


Solution

  • I wanted to ignore the annotations from api doc, but it wasn't possible. Instead I can ignore the annotations from doctrine

    /**
     * @IgnoreAnnotation("apiName")
     * @IgnoreAnnotation("apiDefine")
     * @IgnoreAnnotation("apiGroup")
     * @IgnoreAnnotation("apiParam")
     * @IgnoreAnnotation("apiSuccess")
     */
    class UserController extends ControllerBase
    

    The only downside that I see is the need to add it for each files.