- Add
hooks
configuration into extra segment of composer.json:
"extra": {
"hooks": {
"pre-commit": [
"./vendor/bin/php-cs-fixer fix",
"git add -u"
]
}
}
- Add scripts into scripts segment of composer.json:
"scripts": {
"lint": "./vendor/bin/php-cs-fixer fix --dry-run --verbose",
"lint:fix": "./vendor/bin/php-cs-fixer fix",
"hook": "./vendor/bin/cghooks update"
}
- Install requirements and setup pre-commit hook:
composer require --dev brainmaestro/composer-git-hooks friendsofphp/php-cs-fixer
composer hook
- Create configuration file
.php_cs
and set rules:
Change folders and rules if you want. You are welcome :)
<?php
return PhpCsFixer\Config::create()
->setUsingCache(false)
->setRiskyAllowed(true)
->setRules([
'@PhpCsFixer' => true,
'phpdoc_summary' => false,
'concat_space' => [
'spacing' => 'one',
],
'psr0' => true,
])
->setFinder(PhpCsFixer\Finder::create()
->files()
->in(__DIR__.'/app')
->in(__DIR__.'/config')
->in(__DIR__.'/routes')
->in(__DIR__.'/tests')
->name('*.php')
);
- Create your first commit :)
You can run autofixing without changes in files, just for reporting:
composer lint