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

Throw an error on service names that are invoked but missing

Open mglaman opened this issue 3 years ago • 4 comments

Right now there are no errors if you call entity.manager from the service container in D9. That is because we do not error when there is a service miss. We should throw an error.

HOWEVER this would error on dynamically defined services in service providers or compiler passes.

mglaman avatar Oct 06 '21 19:10 mglaman

Maybe we can add a list of known services to return an error on when a specific Drupal version is used.

mglaman avatar Oct 06 '21 19:10 mglaman

To take into account the dynamically defined services, phpstan-symfony use the dumped container. Drupal use a php array dumper because it needs the dynamic part (when installing a module for instance the container needs to be rebuilt) and do not store it in a file accessible like Symfony does, but maybe we could ask people to do an extra step by dumping the container in a file and configure phpstan-drupal if they want to use this rule? 🤔

Just thinking out loud.

brambaud avatar Nov 12 '21 12:11 brambaud

You're right. Usually in my experience dynamic services are usually event subscribers, or things not manually injected. So that'd be a problem

mglaman avatar Nov 13 '21 02:11 mglaman

If this moves forward, it should only be behind a flag and opt-in. That way end users can choose to turn this on. Their code has more control and probably does not have dynamic service declarations.

mglaman avatar May 10 '23 20:05 mglaman