You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP CS Fixer:修复Laravel Kernel文件中数组键与箭头指针间空格异常添加问题

Fixing PHP CS Fixer's Unwanted Spaces Between Array Keys and => in Laravel Kernel

Hey, I know exactly what's going on here. The @PSR2 rule set you're using enforces spaces around the => operator in arrays, which is why your clean, no-space format is getting messed up after running PHP CS Fixer.

To override this behavior and keep your array keys and => operator tight (no spaces in between), you just need to add the binary_operator_spaces rule to your configuration. This lets you explicitly define how spacing works for specific operators, overriding the PSR2 defaults.

Here's your updated config with the fix included:

$config->setRules([
    '@PSR2' => true,
    'array_syntax' => ['syntax' => 'short'],
    'ordered_imports' => ['sort_algorithm' => 'length'],
    'no_unused_imports' => true,
    // This rule forces no spaces around the => operator
    'binary_operator_spaces' => [
        'operators' => [
            '=>' => 'none',
        ],
    ],
])
->setIndent("\t")
->setFinder($finder);

Once you update your config and run PHP CS Fixer again, your $routeMiddleware array will go back to your preferred format—no extra spaces between keys and =>.

内容的提问来源于stack exchange,提问作者secondman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 17:32:37