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

DrushStyle warnings with Drush 11

Open neclimdul opened this issue 2 years ago • 2 comments

Don't know if this is something for this project but it seems like it might be able to help. When using DrushStyle with recent versions of Drush 11 you'll run into this problem:

 ------ --------------------------------------------------------------------- 
  Line   web/modules/custom/my_custom/src/Commands/DrushCommandBase.php     
 ------ --------------------------------------------------------------------- 
  20     Instantiated class Drush\Style\DrushStyle not found.                 
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols  
 ------ ---------------------------------------------------------------------

This is caused by a fix they added dynamically load different classes to support Symfony 6 and changed method signatures. 06eb4a45296e409c6af9b592d8bec0f555adedd8 Looking at the commit there are a number of other classes this would affect as well.

The problem seems to be that the class lives outside packagist autoloading so phpstan isn't picking it up. Drush is adding the root dynamically during preflight sort of like drupal module namespaces but based on the detected Symfony version which... could make things complicated.

neclimdul avatar May 31 '22 21:05 neclimdul

If anyone one else runs into this, the immediate fix to get a analysis passing again was to add this to phpstan.neon.

  scanDirectories:
    - vendor/drush/drush/src-symfony-compatibility/v4

Replace v4 with v6 if you're testing things in D10.

neclimdul avatar May 31 '22 21:05 neclimdul

Ah yeah, the Symfony compatibility folder. I ran into this during a live stream with some other problem but cannot remember how it was worked around.

mglaman avatar Jun 01 '22 12:06 mglaman