Skip to content

Fix PHPStan excludes for sites/*/files descendants#8

Merged
UltraBob merged 1 commit intomainfrom
feature/phpstan-exclude-sites-files
Feb 21, 2026
Merged

Fix PHPStan excludes for sites/*/files descendants#8
UltraBob merged 1 commit intomainfrom
feature/phpstan-exclude-sites-files

Conversation

@UltraBob
Copy link
Owner

The Issue

PHPStan 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

  • Updates shipped PHPStan config amendment exclude path to include descendants:
    • __DOCROOT__/sites/*/files/*
  • Updates wrapper fallback exclude paths in commands/web/phpstan to the same descendant pattern.
  • Adds a behavioral Bats test that creates a nested file under web/sites/default/files/... and verifies it is not included in ddev phpstan --debug output.

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.neon excludes manually.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
assert_failure
assert_success

Copilot uses AI. Check for mistakes.
@UltraBob UltraBob merged commit fa46d6b into main Feb 21, 2026
7 checks passed
@UltraBob UltraBob deleted the feature/phpstan-exclude-sites-files branch February 21, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PHPStan scans web/sites/*/files descendants on Drupal CMS installs, causing noisy false-positive output

2 participants