phpstan-drupal icon indicating copy to clipboard operation
phpstan-drupal copied to clipboard

Provide `service-id-string` for service ID parameters

Open mglaman opened this issue 3 years ago • 2 comments

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.

mglaman avatar Apr 30 '22 17:04 mglaman

Okay, so this is not yet implemented :) (I have just had a need for something similar.)

mxr576 avatar Jan 30 '24 09:01 mxr576

I started working on it and dead-ended. I may try to pick it back up. It's been a while

mglaman avatar Jan 31 '24 00:01 mglaman