composer require --dev dbt/php-cs-fixer-config
If you don't already have a .php_cs.dist.php
configuration file, create one in your project root:
touch .php_cs.dist.php
Then fill it out:
<?php
use Dbt\PhpCsFixerConfig\Loader;
use PhpCsFixer\Finder;
$finder = Finder::create()->in([
__DIR__ . '/src',
// Add your own directories here.
]);
// If you want to add your own rules. If you specify a rule that already exists
// in the base ruleset, your local rule will take precedence and override the
// base rule.
$localRules = require(__DIR __ . '/rules.php');
$loader = Loader::new($finder, $localRules);
// If you want to turn off risky tests.
$loader->disallowRisky();
return $loader->getConfig();
You can optionally add Composer scripts to your composer.json
so you don't have to run PHP-CS-Fixer from your vendor directory each time. For example:
{
"scripts": {
"cs": "php-cs-fixer fix",
"cs-dry": "php-cs-fixer fix --dry-run"
}
}
https://www.jetbrains.com/help/phpstorm/using-php-cs-fixer.html
If you wish to use GrumPHP to ensure code checks run pre-commit, you can do something like the following:
Install GrumPHP:
composer require --dev phpro/grumphp
Add a configuration file:
touch grumphp.yml
Fill it out, for example:
parameters:
ascii: ~
tasks:
phpcsfixer2:
config: '.php_cs.dist.php'
MIT. Do as you wish.