mglaman / phpstan-drupal

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

Add check for "Manually created services must specify public or private" #439

Open mxr576 opened 2 years ago

mxr576 commented 2 years ago

https://www.drupal.org/node/3194517

Captured this in Behat tests:

Not marking service definitions as public is deprecated in drupal:9.2.0 and is required in drupal:10.0.0. Call $definition->setPublic(TRUE) before calling ::setDefinition(). See https://www.drupal.org/node/3194517: 4x
    2x in ConfigFilterServiceProvider::alter from Drupal\config_filter
    2x in IdentitySourceCollectorCompilerPass::process from Drupal\xy\DependencyInjection

I guess this in a runtime deprecation warning that cannot be checked by PHPStan deprecations, therefore we need a custom rule for that.

mglaman commented 2 years ago

This could be very hard. Just like entity query access.

mxr576 commented 2 years ago

Is it? Don't we just need to analyze implementation of \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface::process() and identify if they added any new service definition without marking it public? (Just thinking aloud)

mglaman commented 2 years ago

Well, I think we actually need to listen to calls of setDefinition and check the arguments. And even then, we may not have enough information. We may need to leverage dynamic return type extensions like the entity query work, where we modify what the type is considered internally to PHPStan.