Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Associative array align => with PHP-CS-Fixer

Tags:

php

phpcs

Should associative array => should be align with PHP-CS-Fixer ?

$array = [
    1    => 'a',
    '1'  => 'b',
    1.5  => 'c',
    true => 'd',
];

or

$array = [
    1 => 'a',
    '1' => 'b',
    1.5 => 'c',
    true => 'd',
];

I didn't find filter for that in https://github.com/FriendsOfPHP/PHP-CS-Fixer

like image 539
Bouffe Avatar asked Nov 12 '15 11:11

Bouffe


2 Answers

This is now a proper way to run the align_double_arrow with newer versions of PHP-CS-Fixer (v2, v3), which will align array elements after the double arrow ('=>'):

php-cs-fixer fix path \
--rules='{"binary_operator_spaces": {"operators": {"=>": "align_single_space_minimal"}}}'

More to read: https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/3.0/doc/rules/operator/binary_operator_spaces.rst

like image 75
boryn Avatar answered Oct 02 '22 12:10

boryn


Filter for that is align_double_arrow

like image 31
Bouffe Avatar answered Oct 02 '22 12:10

Bouffe