Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service arguments are not verified against class __construct() #465

Open
brad8506 opened this issue Aug 9, 2022 · 2 comments
Open

Service arguments are not verified against class __construct() #465

brad8506 opened this issue Aug 9, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@brad8506
Copy link

brad8506 commented Aug 9, 2022

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 brad8506 changed the title Service arguments are not verified against __construct() Service arguments are not verified against class __construct() Aug 9, 2022
@mglaman
Copy link
Owner

mglaman commented Aug 16, 2022

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 mglaman added the enhancement New feature or request label May 10, 2023
@mglaman
Copy link
Owner

mglaman commented May 10, 2023

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 mglaman pinned this issue May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants