🏗 Getting started is easy!
Install php-cs-fixer
mkdir -p tools/php-cs-fixer
composer require --working-dir=tools/php-cs-fixer friendsofphp/php-cs-fixer
Create a .php-cs-fixer.dist.php
configuration file. (these rules are just a suggestion!)
<?php
$finder = (new PhpCsFixer\Finder())
->in(__DIR__);
return (new PhpCsFixer\Config())
->setRules([
'@PhpCsFixer' => true,
'@DoctrineAnnotation' => true,
'blank_line_before_statement' => ['statements' => ['return']],
'concat_space' => ['spacing' => 'one'],
'declare_parentheses' => true,
'global_namespace_import' => true,
'increment_style' => false,
'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'],
'phpdoc_line_span' => ['property' => 'single'],
'phpdoc_separation' => false,
'phpdoc_summary' => false,
'php_unit_internal_class' => false,
'php_unit_test_class_requires_covers' => false,
'single_line_throw' => false,
'yoda_style' => false,
])
->setFinder($finder);
Run the fixer
./tools/php-cs-fixer/vendor/bin/php-cs-fixer fix
That's all, re-run the fixer anytime files change!