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

Having Abstract Classes in Same File as Annotation/Attribute Classes Breaks PHPStan Discovery #1021

Closed
BusterNeece opened this issue Dec 12, 2021 · 4 comments · Fixed by #1024

Comments

@BusterNeece
Copy link
Contributor

I've been in the process of updating my codebase over to version 4.x (and along with it, PHP 8.1), and with 4.0.4 I've discovered that PhpStan is very much not happy about the fact that the AbstractOpenApi class, for one example, is in the same file as OpenApi, which prevents it from auto-discovering it properly. In my code, for type-correctness, I need to return OpenApi, which is why it's throwing that same error in my codebase as well.

In general, I'm noticing both PhpStorm and PhpStan are really having a hard time coming to terms with the way the code is structured in 4.0.x. PhpStorm keeps telling me there's multiple versions of each class, even though one version should never be executed in my code (it can't quite figure that out).

@DerManoMann
Copy link
Collaborator

Sigh. Yes, I know. It was the simplest solution and coding and testing all by myself I never ran into these problems 😋
Maybe I really should look into this again...

@BusterNeece
Copy link
Contributor Author

The workaround in my case was to add, to the phpstan config:

parameters:
    scanDirectories:
       - ./vendor/zircote/swagger-php/src/Annotations

This was referenced Dec 13, 2021
@bbaga
Copy link

bbaga commented Dec 20, 2021

For whatever reason, the above solution didn't work for me. To fix the Class OpenApi\Annotations\AbstractOpenApi was not found while trying to analyse it error, I had to use the scanFiles option:

parameters:
    scanFiles:
        - ./vendor/zircote/swagger-php/src/Annotations/OpenApi.php

@DerManoMann
Copy link
Collaborator

The PR to split annotations and attributes should definitely help as it doesn't even have abstract annotation classes any more 🤷

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

Successfully merging a pull request may close this issue.

3 participants