We can provide custom PHPStan PHPDoc types. This could help us replace the dynamic return type extension DrupalServiceDynamicReturnTypeExtension. This can allow us to validate known service names as arguments.
@phpstan-param service-name-string $id
Then, maybe, we can tie it into templates for returning the class object type.
Such as the following in a stub of \Drupal::service
@phpstan-param service-name-string<T> $id
@return T
If our extension to provide service-name-string is able to provide the value of T for the template, it might just work.
We can provide custom PHPStan PHPDoc types. This could help us replace the dynamic return type extension DrupalServiceDynamicReturnTypeExtension. This can allow us to validate known service names as arguments.
Then, maybe, we can tie it into templates for returning the class object type.
Such as the following in a stub of
\Drupal::service
If our extension to provide
service-name-string
is able to provide the value ofT
for the template, it might just work.