-
-
Save appkr/292a8df74313352287ba7c0c24932a14 to your computer and use it in GitHub Desktop.
php-cs-fixer git pre commit hook
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
<?php | |
return PhpCsFixer\Config::create() | |
->setRules([ | |
'@PSR2' => true, | |
'array_syntax' => ['syntax' => 'short'], | |
'protected_to_private' => false, | |
'mb_str_functions' =>true, | |
]); |
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
#!/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