#!/bin/bash
## Description: Run PHPStan on the ai_governance module, matching GitLab CI (the module's phpstan.neon, else gitlab_templates' default).
## Usage: phpstan-module [phpstan args...]
## Example: "ddev phpstan-module"

set -e
cd /var/www/html

CONFIG=$(mktemp /tmp/phpstan-ci-equivalent.XXXXXX.neon)
trap 'rm -f "$CONFIG"' EXIT
cat > "$CONFIG" <<'EOF'
parameters:
    level: 0
    fileExtensions:
        - php
        - module
        - inc
        - install
        - theme
        - profile
    reportUnmatchedIgnoredErrors: false
    ignoreErrors:
        # new static() is a best practice in Drupal, so we cannot fix that.
        - "#^Unsafe usage of new static#"
EOF
# Like gitlab_templates, prefer the project's own phpstan.neon when it has one.
# (Not via $CONFIG: the trap above deletes that file.)
MODULE_CONFIG=web/modules/custom/ai_governance/phpstan.neon
[ -f "$MODULE_CONFIG" ] || MODULE_CONFIG=$CONFIG

vendor/bin/phpstan analyse web/modules/custom/ai_governance \
  -c "$MODULE_CONFIG" \
  --autoload-file=/var/www/html/vendor/autoload.php \
  "$@"
