Search code examples
phpphp-cs-fixer

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


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


Solution

  • 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"
       }
    }