#!/bin/bash

## Command provided by https://github.com/ddev/ddev-drupal-contrib
## Description: Run phpstan inside the web container
## Usage: phpstan [flags] [args]
## Example: "ddev phpstan" or "ddev phpstan -n"
## ExecRaw: true

if ! command -v phpstan >/dev/null; then
  echo "phpstan is not available. You may need to 'ddev poser'"
  exit 1
fi
test -e phpstan.neon || curl -OL https://git.drupalcode.org/project/gitlab_templates/-/raw/default-ref/assets/phpstan.neon
# Add an empty baseline file to ensure it exists.
test -e phpstan-baseline.neon || touch phpstan-baseline.neon

BASE_DIR=$(dirname "$DDEV_DOCROOT")
phpstan analyse $BASE_DIR "$@"
