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

ModuleHandler->loadInclude() call is not being processed

Open weitzman opened this issue 1 year ago • 4 comments

Bug report

Drush is getting started with phpstan. I'm using latest versions and configured with a drupal_root but the code below is still warning: Function locale_translation_flush_projects not found..

Code snippet that reproduces the problem

https://github.com/drush-ops/drush/blob/accaf08af5b2bd399f0a4fd8f8b7520074344248/src/Commands/core/LocaleCommands.php#L70-L76

weitzman avatar Mar 25 '24 01:03 weitzman

One special thing about Drush is that it lives in the vendor dir, not within the drupal docroot. I wouldnt expect that to matter since I've provided drupal_root parameter but I thought I would mention it.

weitzman avatar Mar 25 '24 13:03 weitzman

Anyone wanting to work on this could clone drush, comment out these 2 lines, and run vendor/bin/phpstan. You will see warnings when you should not.

weitzman avatar Mar 25 '24 19:03 weitzman

I'm not sure why this wouldn't work in Drush. \mglaman\PHPStanDrupal\Rules\Drupal\LoadIncludes checks for the loadInclude method being invoked on anything implementing ModuleHandlerInterface.

I saw the output for this, and there are no errors from the rule (like file not found) which can only happen when:

  • The above checks fail, so the rule is skipped
  • The module and filename cannot be determined
  • The file is included

mglaman avatar Sep 27 '24 10:09 mglaman

Hey @weitzman,

The fix is to add the following to your distribution neon. I have a pull request for drush incoming.

rules:
    - mglaman\PHPStanDrupal\Rules\Drupal\LoadIncludes

andyg5000 avatar Sep 27 '24 12:09 andyg5000