Skip to content

Instantly share code, notes, and snippets.

@mglaman
Last active November 24, 2023 10:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mglaman/240f742a5aea69cdcc5a209391be8c5a to your computer and use it in GitHub Desktop.
Save mglaman/240f742a5aea69cdcc5a209391be8c5a to your computer and use it in GitHub Desktop.
PHPStan configuration for Drupal 7 – https://youtu.be/9HYwq5jq4Sk
parameters:
level: 0
excludePaths:
- '*.api.php'
- '*.database.php'
scanFiles:
- web/authorize.php
- web/cron.php
- web/index.php
- web/update.php
- web/xmlrpc.php
# A quirk with functions that return values by reference &batch_get
# and &views_get_page_view. The problem resolves if the file is specifically scanned.
- web/includes/form.inc
# - web/sites/all/modules/contrib/views/views.module
scanDirectories:
- web/includes
- web/misc
- web/modules
- web/profiles
- web/themes
- web/sites/all
fileExtensions:
- module
- theme
- inc
- install
- profile
- engine
- test
@opdavies
Copy link

opdavies commented Jan 6, 2021

Thanks for this, Matt.

@opdavies
Copy link

opdavies commented Jan 6, 2021

Would it be worth including the test extension for Simpletest tests?

@mglaman
Copy link
Author

mglaman commented Jan 6, 2021

@opdavies oh! I totally forgot that was a thing. I updated it.

@benjifisher
Copy link

benjifisher commented Sep 8, 2022

Thanks for sharing this config file! Here are a few notes from a n00b:

  • With recent versions of PHPStan, use excludePaths instead of excludes_analyse.
  • To check what needs to be updated for PHP 8, add something like phpVersion: 80100.
  • If the configuration file is in the root directory, make sure you run phpstan from there, or add the --configuration (short form -c) option. Look for "Note: Using configuration file ..." at the top of the command's output.

I ran into the last point when using DDev: by default, ddev ssh changes to the web/ directory.

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment