PHP CS Fixer:修复Laravel Kernel文件中数组键与箭头指针间空格异常添加问题
=> 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

