Php-cs-fixer: 'braces' with option 'position_after_functions_and_oop_constructs' = 'next' does not work for multi line methods

Created on 27 Mar 2018  ·  3Comments  ·  Source: FriendsOfPHP/PHP-CS-Fixer

When reporting an issue (bug) please provide the following information:

The PHP version you are using ($ php -v):

=> php 7.1.13

PHP CS Fixer version you are using ($ php-cs-fixer -V):

=> .PHP CS Fixer 2.10.0

The command you use to run PHP CS Fixer:

=> fix

The configuration file you are using, if any:

=>'braces' => [
                'allow_single_line_closure' => true,
                'position_after_anonymous_constructs' => 'same',
                'position_after_functions_and_oop_constructs' => 'next',
                'position_after_control_structures' => 'same',
            ],

If applicable, please provide minimum samples of PHP code (as plain text, not screenshots):

  • before running PHP CS Fixer (no changes):
=> private function __construct(
    argument 1,
    argument 2,
    argument 3,
    argument 4
) 
{
}
  • with unexpected changes applied when running PHP CS Fixer:
=> private function __construct(
    argument 1,
    argument 2,
    argument 3,
    argument 4
) {
}
  • with the changes you expected instead:
=> private function __construct(
    argument 1,
    argument 2,
    argument 3,
    argument 4
) 
{
}
kinfeature request

Most helpful comment

@julienfalque if this is the intended behavior, then the option should be removed.

Because it says clearly "position after functions and oop constructs" and this statement has nothing to do with PSR-2. In fact, I would argue that this fixer handles a superset of PSR-2, as it is supposed (at least as I read it) both versions.

All 3 comments

I think this is the expected behavior: the fixer was implemented with PSR-2 in mind:

When the argument list is split across multiple lines, the closing parenthesis and opening brace MUST be placed together on their own line with one space between them.

Maybe the documentation of the fixer should be updated to be more explicit about this. We could also implement a new option to enable the behavior you want, though I'm not a big fan, let's see if more people need it.

Thanks @julienfalque
i've tried something and opened a pull request..! Let's see if my pull request is qualified enough to merge #3677

Although it didn't pass all the checks.

@julienfalque if this is the intended behavior, then the option should be removed.

Because it says clearly "position after functions and oop constructs" and this statement has nothing to do with PSR-2. In fact, I would argue that this fixer handles a superset of PSR-2, as it is supposed (at least as I read it) both versions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

carusogabriel picture carusogabriel  ·  3Comments

EvgenyOrekhov picture EvgenyOrekhov  ·  3Comments

amitbisht511 picture amitbisht511  ·  3Comments

kcloze picture kcloze  ·  3Comments

EvgenyOrekhov picture EvgenyOrekhov  ·  3Comments