#!/bin/sh
# Run PHP Code Beautifier and Fixer (phpcbf) before committing

# Step 1: Run PHP_CodeSniffer Fixer to auto-fix issues (excluding vendor directory)
echo "Running PHP Code Beautifier and Fixer (phpcbf)..."
./vendor/bin/phpcbf

# If phpcbf makes any changes, abort the commit to allow user to review and re-stage files
if [ $? -ne 0 ]; then
  echo "phpcbf has fixed some issues. Please review and re-stage the files."
  exit 1
fi

# Step 2: Run PHP_CodeSniffer to check for remaining issues (in check mode)
./vendor/bin/phpstan analyse