phpstan-drupal
phpstan-drupal copied to clipboard
Throw an error on service names that are invoked but missing
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.
Maybe we can add a list of known services to return an error on when a specific Drupal version is used.
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.
You're right. Usually in my experience dynamic services are usually event subscribers, or things not manually injected. So that'd be a problem
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.