phpphp-cs-fixer

php-cs-fixer : keep brace on the same line of function declaration


Php cs fixer is doing :

function foobar()
{
....
}

and I want:

function foobar() {
....
}

I can't see what is the config to keep braces on the same line in my config .php_cs file, nor on https://github.com/FriendsOfPHP/PHP-CS-Fixer. I'm using php-cs-fixerV2.

My config file: https://pastebin.com/v03v9Lb5


Solution

  • You have PSR-2 enabled, which requires the braces on the next line. From the documentation it looks like you can set braces.position_after_functions_and_oop_constructs to same (default would be next):

    • position_after_functions_and_oop_constructs ('next', 'same'): 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'

    myconfig.php_cs:

        'braces' => array(
            'allow_single_line_closure' => true,
            'position_after_functions_and_oop_constructs' => 'same',
        ),