Skip to content

ModuleHandler->loadInclude() call is not being processed #741

Closed

Description

@weitzman

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

Activity

  1. changed the title [-]ModuleHandler->loadInclude() call must not be picked up[/-] [+]ModuleHandler->loadInclude() call is not being processed[/+] on Mar 25, 2024
  2. weitzman commented on Mar 25, 2024

    @weitzman
    Author

    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.

  3. weitzman commented on Mar 25, 2024

    @weitzman
    Author

    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.

  4. mglaman commented on Sep 27, 2024

    @mglaman
    Owner

    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
  5. andyg5000 commented on Sep 27, 2024

    @andyg5000

    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
    
  6. mglaman commented on Nov 10, 2026

    @mglaman
    Owner

    The cause: the include files that loadInclude() loads are loaded by the LoadIncludes rule, which is in rules.neon. Drush's config included only extension.neon, so the rule never ran and locale_translation_flush_projects() was unknown. Registering LoadIncludes by hand, as Drush did, fixes it. So does including rules.neon.

    #1096 updates the README's manual installation section to include both files and to explain what breaks without rules.neon.

    @weitzman one more note on Drush's phpstan.neon.dist: src/Commands/core/LanguageAddCommand.php is excluded with "Unclear why the phpstan-drupal rule is not working for this command". That isn't this issue. Its loadInclude() calls work. The function that fails is drush_locale_translation_default_update_options(), which Drush defines in its own includes/legacy.inc, so PHPStan needs it in scanFiles:

    parameters:
        scanFiles:
            - includes/legacy.inc
  7. added a commit that references this issue on Nov 10, 2026
    75372f1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions