为何使用PhpStorm的Reformat Code功能时部分方法格式不一致?
解决PhpStorm中Laravel方法格式不一致的问题
可以实现统一格式,调整以下PhpStorm代码风格设置即可:
- 打开设置面板(快捷键
Ctrl+Alt+S,或顶部菜单File > Settings) - 进入
Editor > Code Style > PHP设置项 - 切换到Wrapping and Braces标签页,调整几个关键选项:
- 在「Method modifiers」区域,勾选
Place 'function' keyword on the same line as modifiers,同时设置Wrap modifiers为「Do not wrap」,确保public等修饰符和function在同一行 - 在「Method declaration parameters」区域,设置
Wrap when typing reaches right margin为「Do not wrap」,避免参数单独换行 - 在「Method return type」区域,勾选
Place return type on the same line as method name,让返回类型和方法名保持在同一行
- 在「Method modifiers」区域,勾选
调整完成后点击「Apply」保存设置,再选中文件内容执行Reformat Code(快捷键Ctrl+Alt+L),所有方法就会统一成你想要的第一种紧凑格式。
内容的提问来源于stack exchange,提问作者mstdmstd
相关产品推荐
相关产品推荐

