Closed Seldaek closed 1 year ago
@Seldaek After the latest commit in dev-master, PHPStan now reports different result with your code snippet:
@@ @@
33: Property Monolog\Handler\Handler::$foo has unknown class Monolog\Processor\Record as its type.
-38: Return typehint of method Monolog\Handler\Handler::foo() has invalid type Monolog\Processor\Record.
+38: Method Monolog\Handler\Handler::foo() has invalid return type Monolog\Processor\Record.
39: Method Monolog\Handler\Handler::foo() should return Monolog\Processor\Record but returns array<string, string>.
I got the same. Should we be able to define types in traits and use them elsewhere or not?
edit:
Defining a @phpstan-type
and then using it in the same trait does not work as well. For example: https://phpstan.org/r/bb19adc4-c0cb-4007-bd7c-b727b7faa8ab
another example: https://phpstan.org/r/b07cd15e-abad-4f73-a077-bc4c56df24fe
Wanted to add a new issue but found this one which seems to be the same underlying issue:
Traits don't use @phpstan-type or @phpstan-import-type
Another example showing the difference when using a trait and when using classes
https://phpstan.org/r/a3d8e137-cb3b-40aa-ac5c-31d13f5368dc
@Seldaek did you find a workaround for this issue by any chance ?
Nope I resolved this by using value objects and removing type aliases :)
I'm experiencing the same issue. (https://phpstan.org/r/3a11ea33-8d1e-4928-9266-bfe23b3341ec)
I think I've just run into this problem, here's another example of this https://phpstan.org/r/cefffe00-ce91-42c6-9b2d-feaf723fb4e9
Has anyone found a solution?
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Bug report
It appears that type aliases get resolved from the scope of the class they are used in, and not from the trait's main docblock.
Code snippet that reproduces the problem
https://phpstan.org/r/fb90214f-4b8d-4f62-87b9-1680ee2afcfa
Expected output
No error.