Php-cs-fixer: Issue between method_chaining_indentation and array_indentation

Created on 17 Jan 2019  路  2Comments  路  Source: FriendsOfPHP/PHP-CS-Fixer

When applying array_indentation and method_chaining_indentation rules, PHP CS Fixer needs to run twice:

first run:

 function foo($foo)
 {
     $foo
         ->bar()
-            ->baz([
+        ->baz([
                 'foo' => 'bar',
             ])
     ;
 }

second run:

 function foo($foo)
 {
     $foo
         ->bar()
         ->baz([
-                'foo' => 'bar',
-            ])
+            'foo' => 'bar',
+        ])
     ;
 }

This seems to be a regression in version 1.13.2 as version 1.13.1 applies all changes at first run.

kinbug

Most helpful comment

As I was the culprit, I created PR #4276 to fix my boo-boo 馃槄

All 2 comments

I think this is caused by #4084 (sorry 馃槣) where method_chaining_indentation got a priority, which is actually the same as array_indentation. I think in your case array_indentation runs first, whereas method_chaining_indentation seems to need to run first.

However, this might produce issues when you are chaining _inside_ an array. I do think your situation is more common though, so the solution is to either give method_chaining_indentation a +1 or array_indentation a -1. (And of course couple the priority, with given example as testcase.)

The lowest version this applies to is 2.12.5

As I was the culprit, I created PR #4276 to fix my boo-boo 馃槄

Was this page helpful?
0 / 5 - 0 ratings