Closed tyteen4a03 closed 1 year ago
This sounds like a psalm/phpstan/jetbrains feature request...
There needs to be @template
annotations in place on Prophecy's side.
For phpstan, you can use https://packagist.org/packages/jangregor/phpstan-prophecy which provides the stubs for the generics, and also extra extensions for better support of the magic calls.
Due to our signature based on magic calls (and the additional extra magic of Argument::cetera()
), I don't think we can make our code statically analysable based only on phpdoc, without relying on a phpstan extension.
But adding @template
on ObjectProphecy would at the very least allow PHPStorm (and maybe other IDEs) to consider the types too, and not raise inspections everywhere, no ?
Or is there a way to point the stub files in the extension (which I'm using) to PHPStorm so it reads it ?
With @phpstan-this-out
being implemented in phpstan 1.9.0, it becomes possible to represent the behavior of willImplement()
in phpdoc.
The phpstan extension will still be necessary to support our API based on magic calls.
I think we can/should import some subset of the types from those stubs, then users would get some benefit from them even without the extension (which probably would still be needed)
It would be amazing if we could typehint our prophecies with Generics phpdoc: