5

关联数组 => 应该与 PHP-CS-Fixer 对齐吗?

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

或者

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

我在https://github.com/FriendsOfPHP/PHP-CS-Fixer中没有找到过滤器

4

2 回答 2

6

现在这是使用较新版本的 PHP-CS-Fixer (v2, v3) 运行的正确方法align_double_arrow,它将在双箭头 ('=>') 之后对齐数组元素:

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

更多阅读: https ://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/3.0/doc/rules/operator/binary_operator_spaces.rst

于 2021-03-31T10:56:07.957 回答
5

过滤器是align_double_arrow

于 2015-11-12T11:52:11.480 回答