Skip to content

Instantly share code, notes, and snippets.

@airtonzanon
Created December 8, 2023 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save airtonzanon/1b8ceb3ceb2c38a5dd66c76687dec015 to your computer and use it in GitHub Desktop.
Save airtonzanon/1b8ceb3ceb2c38a5dd66c76687dec015 to your computer and use it in GitHub Desktop.
PHPSTAN + PHPCS FIX - .git/hooks/pre-commit
fileList=$(git diff --cached --name-only)
phpFileList=$(echo "$fileList" | grep -E '\.(php)$')
if [ ${#phpFileList} -gt 0 ]; then
git stash --keep-index --include-untracked
if ! docker exec YOUR_CONTAINER php -d memory_limit=4G vendor/bin/phpstan analyse ${phpFileList[*]} "$@"; then
git stash pop
exit 1
fi
docker exec YOUR_CONTAINER php-cs-fixer fix --allow-risky=yes && git add .
git stash pop
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment