Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions commands/web/phpstan
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ DEFAULT_PATHS=()
EXCLUDE_PATHS=(
"${DOCROOT}/modules/contrib"
"${DOCROOT}/themes/contrib"
"${DOCROOT}/sites/*/files"
"sites/*/files"
"${DOCROOT}/sites/*/files/*"
"sites/*/files/*"
)
# Prefer explicit project configs before falling back to CI template config.
for config_file in phpstan.neon phpstan.neon.dist phpstan.dist.neon; do
Expand Down
2 changes: 1 addition & 1 deletion drupal-code-quality/config-amendments/phpstan.dcq.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ parameters:
- __DOCROOT__/sites
excludePaths:
analyseAndScan:
- __DOCROOT__/sites/*/files
- __DOCROOT__/sites/*/files/*

# Baseline guidance:
# - Generate a baseline with: ddev phpstan --generate-baseline
Expand Down
27 changes: 25 additions & 2 deletions tests/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ PY
assert_success
run grep -q "docroot/sites" phpstan.neon
assert_success
run grep -q "docroot/sites/\*/files" phpstan.neon
run grep -q "docroot/sites/\*/files/\*" phpstan.neon
assert_success
}

Expand Down Expand Up @@ -1010,10 +1010,33 @@ PY
# Check for excludePaths
run grep -q "excludePaths:" phpstan.neon
assert_success
run grep -q "web/sites/\*/files" phpstan.neon
run grep -q "web/sites/\*/files/\*" phpstan.neon
assert_success
}

@test "phpstan excludes nested files directory descendants" {
set -u -o pipefail
run ddev add-on get "${DIR}"
assert_success

mkdir -p web/sites/default/files/php/twig/test-subdir
cat > web/sites/default/files/php/twig/test-subdir/should-not-scan.php <<'PHP'
<?php

final class DcqPhpstanExcludeProbe {}
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.

case "$output" in
*"test-subdir/should-not-scan.php"*)
echo "Expected phpstan excludePaths to skip files descendants under web/sites/*/files."
return 1
;;
esac
}

@test "cspell config is expanded during installation" {
set -u -o pipefail
run ddev add-on get "${DIR}"
Expand Down