The style you described here is called "the one true brace style" (abbreviated as 1TBS or OTBS).
As I get the exact same problem, I've finally ended here and while @Robbie answer helps, I still needed to search a lot.
So I finally get this .php_cs
in my repository:
<?php
$finder = PhpCsFixer\Finder::create()
//->exclude('somedir')
//->notPath('src/Symfony/Component/Translation/Tests/fixtures/resources.php'
->in(__DIR__)
;
return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'strict_param' => false,
'array_syntax' => ['syntax' => 'long'],
'braces' => [
'allow_single_line_closure' => true,
'position_after_functions_and_oop_constructs' => 'same'],
])
->setFinder($finder)
;
Some explainations (from the (PHP-CS-Fixer README):
- array_syntax to long means
array()
instead of []
. Whether to use the long or short array syntax; defaults to 'long';
- allow_single_line_closure: whether single line lambda notation should be allowed; defaults to false;
- position_after_functions_and_oop_constructs: whether the opening brace should be placed on "next" or "same" line after classy constructs (non-anonymous classes, interfaces, traits, methods and non-lambda functions); defaults to 'next'.
In IDE such Atom, the php-cs-fixer plugin will search for the .php_cs
config file in the root path of the current project. It's also possible to specify the path.
Last but not least, the website of Michele Locati, PHP CS Fixer configuration can really helps.