mglaman / phpstan-drupal

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

Service resolution returns incorrect interface for keyvalue.expirable #394

Closed cmlara closed 1 year ago

cmlara commented 2 years ago

I've encountered a minor issue with the container service resolution returning an incorrect interface when loading the keyvalue.expirable service through the container.

This can be duplicated using just core files with: phpstan analyze --level 3 web/core/lib/Drupal.php

380 Method Drupal::keyValueExpirable() should return Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface but returns Drupal\Core\KeyValueStore\KeyValueStoreInterface.

I've also duplicated this in a plugin implementing ContainerFactoryPluginInterface using $container->get('keyvalue.expirable')->get('something')

cmlara commented 1 year ago

I had originally though this was a phpstan-drupal issue due to an incorrect test case on the PHPStan playground, however after creating a more accurate test case I can see this is able to be duplicated without phpstan-drupal.

https://phpstan.org/r/287481fe-f00d-4b58-94a6-b70542131abf

I'm going to have to look into if this is a Drupal Core issue or a PHPStan issue however this issue can be closed.