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

ContainerInterace::has should never return "always true" #668

Open mglaman opened 11 months ago

mglaman commented 11 months ago

Feature request

Consequence of https://github.com/mglaman/phpstan-drupal/pull/610/

This caused ContainerInterace::has to be "always true", which may lead developers to removing if ($container->has() checks, causing actual bugs. Especially around conditional dependencies.

Slack thread for context: https://drupal.slack.com/archives/C033S2JUMLJ/p1701250878367139

mglaman commented 7 months ago

Actually, this wasn't a consequence of #610; it's been a latent problem for a while

        if ($methodReflection->getName() === 'has') {
            return new ConstantBooleanType($this->serviceMap->getService($serviceId) instanceof DrupalServiceDefinition);
        }
mglaman commented 7 months ago

I think this should be a new bleeding edge toggle to: