Created
December 8, 2023 14:46
-
-
Save airtonzanon/1b8ceb3ceb2c38a5dd66c76687dec015 to your computer and use it in GitHub Desktop.
PHPSTAN + PHPCS FIX - .git/hooks/pre-commit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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