Php-cs-fixer: New Fixer Idea: Equalize Spaces

Created on 26 Sep 2017  路  4Comments  路  Source: FriendsOfPHP/PHP-CS-Fixer

I couldn't find a fixer to convert:

$foo=$bar;

into:

$foo = $bar;

It's entirely possible I'm missing something and the option is there, but I tried a bunch of things and couldn't find one to do this. Is it possible? And, if not, could this be added?

kinquestion

Most helpful comment

Thank you 馃槃

All 4 comments

$ php php-cs-fixer fix test3.php -vvv --dry-run --diff
Loaded config default from "/home/possum/work/PHP-CS-Fixer/.php_cs.dist".
Using cache file ".php_cs.cache".
Paths from configuration file have been overridden by paths provided as command arguments.
F
Legend: ?-unknown, I-invalid file syntax, file ignored, S-Skipped, .-no changes, F-fixed, E-error
   1) test3.php (binary_operator_spaces)
      ---------- begin diff ----------
--- Original
+++ New
@@ @@

-$foo=$bar;
+$foo = $bar;
      ----------- end diff -----------

i.e. binary_operator_spaces will do this, however you need the version that is currently in master and will be part of the upcoming 2.7 release. Just a little bit more waiting :)

Great, thanks 馃憤

Which one of the new options specifies that behaviour?

It will be the default, however you can also defined it explicit like;

'binary_operator_spaces' => [
   'default' => null, // do not fix binary operators unless listed below;
   'operators' => [
        '=' => 'single_space', // do not align `=`, just make sure there is a single space before and after it
    ]
]

Thank you 馃槃

Was this page helpful?
0 / 5 - 0 ratings