compatibility 937 Bytes
#!/usr/bin/env bash

# Disable commands dynamic path.
# shellcheck disable=SC2154

helpFunction()
{
   echo ""
   echo "Usage: ddev compatibility <php version> <directories>"
   echo -e "\tExample: ddev compatibility 8.2 web/modules/custom web/themes/custom"
   exit 1
}

if [ "$#" -lt 2 ]; then
    echo "Illegal number of parameters"
    helpFunction
fi

PHPVER="$1"
shift
DIRECTORY="$@"

# Begin script in case all parameters are correct
FIND="find $DIRECTORY -name '*.php' -or -name '*.module' -or -name '*.install' -or -name '*.theme' -or -name '*.inc' -or -name '*.profile'"
docker run --rm -ti -w "/opt/project" -v `pwd`:/opt/project php:$PHPVER bash -c "$FIND | xargs -n1 /usr/local/bin/php --syntax-check" || true
docker run --rm -ti -w "/opt/project" -v `pwd`:/opt/project droptica/compatibility:latest phpcs --ignore=*.js,*.css -p $DIRECTORY --standard=PHPCompatibility --runtime-set testVersion $PHPVER --report=code || true