以下是在Ubuntu上使用PhpStorm进行代码格式化的技巧:
Ctrl+Alt+L
(Windows/Linux)或Cmd+Option+L
(Mac)进行格式化。File
菜单中的Settings
(或Ctrl+Alt+S
),选择Editor
>Code Style
>PHP
。Settings
中导航到Tools
>Actions on Save
。Reformat code
选项,之后保存文件时会自动格式化。php-cs-fixer
:composer global require friendsofphp/php-cs-fixer
。Settings
中找到File Watchers
,添加自定义文件监视器,选择PHP文件类型,输入php-cs-fixer
路径及参数fix ${FILE_PATH}
。