61 lines
1.6 KiB
Bash
Executable File
61 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
. "$(dirname "$0")/_/husky.sh"
|
|
|
|
# Get the list of staged PHP files
|
|
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.php$')
|
|
|
|
# If there are no staged PHP files, exit
|
|
if [ -z "$STAGED_FILES" ]; then
|
|
echo "No PHP files staged for commit."
|
|
exit 0
|
|
fi
|
|
|
|
# Function to display errors
|
|
display_errors() {
|
|
local errors="$1"
|
|
echo "Errors detected:"
|
|
echo "---------------------------------------"
|
|
echo "$errors" | while IFS='|' read -r file line error; do
|
|
printf "%-60s | %-10s | %s\n" "$file" "$line" "$error"
|
|
done
|
|
echo "---------------------------------------"
|
|
}
|
|
|
|
# Run PHP lint to check for syntax errors
|
|
SYNTAX_ERRORS=0
|
|
echo "Checking PHP syntax errors..."
|
|
for FILE in $STAGED_FILES; do
|
|
php -l "$FILE"
|
|
if [ $? -ne 0 ]; then
|
|
SYNTAX_ERRORS=1
|
|
fi
|
|
done
|
|
|
|
if [ $SYNTAX_ERRORS -ne 0 ]; then
|
|
echo "Syntax errors detected. Please fix them before committing."
|
|
exit 1
|
|
fi
|
|
|
|
# Run PHPCBF to auto-fix issues
|
|
echo "Running PHPCBF..."
|
|
for FILE in $STAGED_FILES; do
|
|
/home/aissel/.config/composer/vendor/bin/phpcbf --standard=/var/www/html/google_forms/phpcs.xml "$FILE" || true
|
|
done
|
|
|
|
# Run PHP CS Fixer to auto-fix issues
|
|
echo "Running PHP CS Fixer..."
|
|
for FILE in $STAGED_FILES; do
|
|
/home/aissel/.config/composer/vendor/bin/php-cs-fixer fix "$FILE"
|
|
done
|
|
|
|
# Re-run PHPCS to check for unresolved coding standard violations
|
|
echo "Running PHPCS..."
|
|
echo "$STAGED_FILES" | xargs -n 1 /home/aissel/.config/composer/vendor/bin/phpcs --standard=/var/www/html/google_forms/phpcs.xml
|
|
|
|
# Add the fixed files back to the staging area
|
|
for FILE in $STAGED_FILES; do
|
|
git add "$FILE"
|
|
done
|
|
|
|
echo "Pre-commit checks completed."
|