Skip to content

Instantly share code, notes, and snippets.

@anwinged
Last active September 13, 2018 12:56
Show Gist options
  • Save anwinged/7cad65afc347b081706a52c336f4acd9 to your computer and use it in GitHub Desktop.
Save anwinged/7cad65afc347b081706a52c336f4acd9 to your computer and use it in GitHub Desktop.
Format changed files with php-cs-fixer
#!/usr/bin/env bash
set -eux
# Executable directories
PATH=bin:tools:${PATH}
# Executable
fixer_command=php-cs-fixer
if command -v php-cs-fixer.sh >/dev/null
then
fixer_command=php-cs-fixer.sh
fi
# Options
set -- \
--path-mode=intersection \
--verbose \
"$@"
if test -r .php_cs
then
set -- --config=.php_cs "$@"
else
if test -r .php_cs.dist
then
set -- --config=.php_cs.dist "$@"
fi
fi
# Changed files
changed_files=$(git diff --diff-filter=d --name-only | grep "\\.php$")
# Run!
${fixer_command} fix "$@" ${changed_files}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment