How to replicate PHPStorm's "Align fields in columns" in PHP-CS-Fixer?

360 Views Asked by At

I would like to know if it is possible to replicate the Align fields in columns behavior from PHPStorm to PHP-CS-Fixer

For having this :

        var    $numbers = ["one", "two", "three", "four", "five", "six"];
        var    $v       = 0;
        public $path    = "root";

        const FIRST  = 'first';
        const SECOND = 0;
        const Z      = -1;

instead of :

        var $numbers = ["one", "two", "three", "four", "five", "six"];
        var $v = 0;
        public $path = "root";

        const FIRST = 'first';
        const SECOND = 0;
        const Z = -1;

Aligning the = is done by using this directive :

'binary_operator_spaces' => [
        'default' => 'align',
        'operators' => ['=>' => 'align']
    ],

But I can't find how to align the variables names as well

2

There are 2 best solutions below

0
On BEST ANSWER

PHP CS Fixer does not have such feature, if you have time to implement I will recommend this as a start.

0
On

I encountered a similar issue and discovered a solution that worked for me. If you're looking to configure the spacing around binary operators in your code, specifically for aligning the => operator based on scope, you can use the following configuration snippet:

"binary_operator_spaces": {
   "operators": {
       "=>": "align_by_scope"
   }
}