phpstan/phpstan-symfony

[Feature Request] Overriding dynamic service return types

keulinho opened this issue · 0 comments

Currently there is no way to override dynamic service return types on the container that are specified in ServiceDynamicReturnTypeExtension.

This is useful to provide more specific information e.g. if the service implement a generic class there is currently no way to teach phpstan that a specific service is of a specific type.

I already build a custom DynamicMethodReturnTypeExtension that adds the generic types, but in the end phpstan makes a union for all types returned by any DynamicMethodReturnTypeExtension. This leads to the less specific type of the smyfony extension "winning" and in fact overriding my more specific type again.

I would like to the a feature where you can specify the phpstan type of a service, or at least mark a service to be ignored by the symfony phpstan extension, so you can write your custom DynamicMethodReturnTypeExtension for those services.

Happy to contribute such a feature, but I'm currently not sure how to best implement this. The only way I see now is adding a custom tag to the service definition and specifying the type there and that type will then take precedence over the class name of the service.