mglaman / phpstan-drupal

Extension for PHPStan to allow analysis of Drupal code.
https://phpstan-drupal.mglaman.dev/
MIT License
196 stars 76 forks source link

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

Open mglaman opened 2 years ago

mglaman commented 2 years ago

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.

mxr576 commented 9 months ago

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

mglaman commented 9 months ago

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