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

Service arguments are not verified against class __construct()

Open brad8506 opened this issue 3 years ago • 2 comments

I noticed an issue where arguments to classes in the services file were not verified against the class->__construct() at any phpstan runlevel. Is this something that would be fixable?

Our error was bought to my attention when I was running drush phpstorm-metadata:generate from project drupal/phpstorm_metadata

image

brad8506 avatar Aug 09 '22 05:08 brad8506

Correct, this is not analyzed. Not on any level of PHPStan, it needs a custom rule. This probably exists in phpstan-symfony, but that package reads the dumped container information.

mglaman avatar Aug 16 '22 00:08 mglaman

I believe PHPStan 1.8.0 made this feasible by using Collectors: https://phpstan.org/developing-extensions/collectors

This would collect on __construct for getNodeType. Then in processNode it would check the service map to see if the class is a service.

Then a custom rule could be applied to check the service definition against the arguments.

mglaman avatar May 10 '23 20:05 mglaman