Skip to content

Instantly share code, notes, and snippets.

@ssaki
Last active January 2, 2018 11:27
Show Gist options
  • Save ssaki/f2df92192fe47143171dd937db049d9a to your computer and use it in GitHub Desktop.
Save ssaki/f2df92192fe47143171dd937db049d9a to your computer and use it in GitHub Desktop.
Customized php-cs-fixer rules and alias
<?php
// Only fix files in the current directory
$finder = PhpCsFixer\Finder::create()
->in(getcwd())
->name('*.php')
->ignoreDotFiles(true)
->ignoreVCS(true)
->depth('== 0')
;
return PhpCsFixer\Config::create()
->setUsingCache(false)
->setRules([
'@Symfony' => true,
'single_import_per_statement' => false,
'concat_space' => ['spacing' => 'one'],
'array_syntax' => ['syntax' => 'short'],
'yoda_style' => false,
'binary_operator_spaces' => [
'operators' => [
'=' => 'align_single_space',
'=>' => 'align_single_space',
],
],
])
->setFinder($finder)
;

Custom configuration for the php-cs-fixer script

Install

composer global require friendsofphp/php-cs-fixer

Configure

  1. Add the provided .php_cs.php file to your home folder
  2. Adjust to match your preferences
  3. Add the following alias to your bash_rc
alias php-cs-fixer='php-cs-fixer fix -v --config ~/.php_cs.php'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment