2

Is there a rule in PHP-CS-FIXER 2.15.3 to align a sequence of equal symbols?

For example to change

    $a = 3;
    $codeWord = 4;
    $foo = 'xyz';

into

    $a        = 3;
    $codeWord = 4;
    $foo      = 'xyz';

?

I have read almost every description of every rule at https://mlocati.github.io/php-cs-fixer-configurator/#version:2.15|configurator but I didn't find any. Did I missed it, or is there actuality no such rule?

Adam
  • 25,960
  • 22
  • 158
  • 247
  • I deleted my comment, saw you were asking about FIXER. I know of no such rule. – Jay Blanchard Sep 26 '19 at 17:22
  • can u please share the purpose? maybe you got alternate suggestions. – devpro Sep 26 '19 at 17:23
  • 1
    @devpro my purpose is pretty primitive. I simply find it looks cleaner when the equal signs are aligned like in the second example. – Adam Sep 26 '19 at 17:24
  • is Tab key not working??? – devpro Sep 26 '19 at 17:37
  • @devpro ofcourse tab key is working. ;) But I would like that they get automatically aligned when I don't do it myself. Thats why I use php-cs-fixer. Before I write my custom script I wanted to find out if this already exists. – Adam Sep 26 '19 at 17:41

1 Answers1

5

You can do it using binary_operator_spaces fixer.

Add it only for = operator with

    'binary_operator_spaces' => ['operators' => ['=' => 'align_single_space']],

or for every binary operator:

    'binary_operator_spaces' => ['default' => 'align_single_space'],
kuba
  • 3,670
  • 3
  • 31
  • 41