Skip to content

Instantly share code, notes, and snippets.

@appkr
Forked from jwage/.php_cs
Last active Feb 11, 2018
Embed
What would you like to do?
php-cs-fixer git pre commit hook
<?php
return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'protected_to_private' => false,
'mb_str_functions' =>true,
]);
#!/usr/bin/env bash
# Must be placed at ".git/hooks/pre-commit" with 755 permission.
echo "php-cs-fixer pre commit hook is starting"
PHP_CS_FIXER="vendor/bin/php-cs-fixer"
HAS_PHP_CS_FIXER=false
if [ -x vendor/bin/php-cs-fixer ]; then
HAS_PHP_CS_FIXER=true
fi
if $HAS_PHP_CS_FIXER; then
git status --porcelain | grep -E "^\s?[AM](.*)\.js$" | cut -c 3- | while read line; do
$PHP_CS_FIXER fix --rules=@PSR2 --allow-risky=yes --path-mode=intersection --verbose "$line";
# OR
# $PHP_CS_FIXER fix --config=.php_cs --allow-risky=yes --path-mode=intersection --verbose "$line";
git add "$line";
done
else
echo ""
echo "Please install php-cs-fixer, e.g.:"
echo ""
echo " composer require --dev \"friendsofphp/php-cs-fixer:2.0.0\""
echo ""
echo " Note. DO NOT install php-cs-fixer to HEAD version, which requires PHP 7.1.3."
echo ""
fi
echo "php-cs-fixer pre commit hook finished"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment