-
-
Notifications
You must be signed in to change notification settings - Fork 938
Description
Bug report
It seems that phpstan sometimes ignores "use X\Y\Z" at the top of files containing traits.
Here's an example of when it gets it right.
https://phpstan.org/r/ea17b95e-eb64-4601-8fca-85224173be48
Notice that the error is "unknown class Andromeda\Apps\Accounts\Account as its type" - this is the correct path that I specified for "use Account". In my codebase, this class exists and there is no error.
But then here, it seems to ignore the "use" and assumes that Account is in the current namespace.
https://phpstan.org/r/397f1e30-54af-4faf-9cbc-78d4028f8b34
Notice that the error is now "unknown class Andromeda\Apps\Files\Policy\Account as its type". In my codebase, I still get this error even though the correct class does exist.
I ignored this for a while because I figured I was doing something wrong, but when I noticed the behavior is inconsistent, I thought it's most likely a bug. Perhaps it's something about the use of templates that confuses it.
Code snippet that reproduces the problem
https://phpstan.org/r/397f1e30-54af-4faf-9cbc-78d4028f8b34
Expected output
Should say "Andromeda\Apps\Accounts\Account" (per the use line), not Andromeda\Apps\Files\Policy\Account (current namespace).
Did PHPStan help you today? Did it make you happy in any way?
Truth be told, I can no longer imagine writing PHP without it.