-
-
Notifications
You must be signed in to change notification settings - Fork 946
Description
Bug report
I'm having a hard time finding the cause of the following issue: I migrated a project from PHP 7.4 to 8.0 and converted all route- and doctrine-annotations to attributes. The code works just fine, but I get "class not found"-issues from phpstan for all (doctrine-)entities that implement an interface when using attributes.
This does not only happen when using the entities as class-members but everywhere in the project:

Some strange things I found out:
- The errors show only in PhpStorm. When executing phpstan in the console, I get the "No errors"-message. I still can't just ignore the errors as somehow also rector is affected as it's using the same phpstan.neon.
- PhpStorm itself finds all classes (also executing PhpStorm's code inspection shows no errors, even though it also lists phpstan-errors), it's just phpstan "inside" PhpStorm. The configuration for phpstan in PhpStorm has not been changed. Also the code runs without errors.
- Only entities that implement an interface are not found (e.g. Stringable or UserInterface/Serializable for an User object), all other doctrine-entities are ok.
- When removing the interface (and the needed methods) the errors disappear (but of course this is not an option).
- When reverting from attributes for the repository (#[\Doctrine\ORM\Mapping\Entity(repositoryClass: UserRepository::class)]) back to annotations (@Orm\Entity(repositoryClass="App\Repository\UserRepository")) all entity-classes are found again.
I'm out of ideas here. Is it PhpStorm or my project-configuration, did something go wrong during the migration? Is this a bug in phpstan or phpstan-doctrine? Is this also related to some (missed) setting in the repository-classes?
I did endless searches for almost two days now, have tried everything I can think of that I may have missed during my migration, but to no avail.
Code snippet that reproduces the problem
https://phpstan.org/r/16989271-d54b-4fc8-9a08-2bff94418999
Note that this snippet only shows a (very reduced) part of my setup but does not reproduce the problem which seems somehow related to PhpStorm. The class "SomeObject" from the snippet would show as "not found" in my project.
Expected output
All entities should be found.
Did PHPStan help you today? Did it make you happy in any way?
Apart from the above issue phpstan (and rector) made the migration from PHP 7.4 to 8.0 a piece of cake :)
