Fix PHPStan excludes for sites/*/files descendants#8
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes PHPStan configuration to properly exclude generated runtime files under web/sites/*/files/ and its subdirectories. Previously, PHPStan scanned these directories on Drupal CMS installs, producing noisy false-positive output. The fix updates the exclude pattern from sites/*/files (directory only) to sites/*/files/* (directory and contents) across configuration files and wrapper scripts.
Changes:
- Updated PHPStan exclude patterns to include
/*suffix for excluding descendants - Added behavioral test validating exclusion of deeply nested files under
sites/*/files/ - Updated existing tests to check for the corrected pattern
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| drupal-code-quality/config-amendments/phpstan.dcq.neon | Updated excludePaths pattern from __DOCROOT__/sites/*/files to __DOCROOT__/sites/*/files/* |
| commands/web/phpstan | Updated fallback EXCLUDE_PATHS patterns to include /* suffix for both absolute and relative paths |
| tests/test.bats | Added new test for nested file exclusion and updated existing tests to verify the corrected pattern |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| PHP | ||
|
|
||
| run ddev phpstan analyse --debug -c phpstan.neon web/sites | ||
| assert_failure |
There was a problem hiding this comment.
The test expects PHPStan to return a non-zero exit code (assert_failure), but if the exclude pattern works correctly and there are no other PHP files with errors in web/sites, PHPStan will likely return exit code 0 (success). Consider changing this to assert_success or removing the assertion entirely, since the primary validation is whether the excluded file appears in the debug output (lines 1032-1037).
| assert_failure | |
| assert_success |
The Issue
web/sites/*/filesdescendants on Drupal CMS installs, causing noisy false-positive output #7PHPStan was scanning generated runtime files under
web/sites/default/files/...on Drupal CMS installs, producing a large amount of noisy output.How This PR Solves The Issue
__DOCROOT__/sites/*/files/*commands/web/phpstanto the same descendant pattern.web/sites/default/files/...and verifies it is not included inddev phpstan --debugoutput.Manual Testing Instructions
ddev add-on get https://github.com/UltraBob/ddev-drupal-code-quality/tarball/refs/pull/8/head ddev restart ddev phpstan analyse --debug -c phpstan.neon web/sites # Confirm no analyzed paths from web/sites/default/files/**Automated Testing Overview
Executed:
bats ./tests/test.bats --filter "phpstan excludes nested files directory descendants"bats ./tests/test.bats --filter "phpstan config includes default paths and excludes after install"bats ./tests/test.bats --filter "install from directory with non-web docroot"Release/Deployment Notes
No deployment steps required beyond shipping a new add-on release. Existing projects can re-run add-on install/update or update
phpstan.neonexcludes manually.