如何在PhpStorm 2021.1.4中配置Laravel链式调用格式化规则?
PhpStorm 2021.1.4 调整Laravel链式调用格式化缩进配置步骤
当前格式化后链式调用缩进效果:
$totalVotesCount = Vote::getByName($filterName, true) ->getByStatus($filterStatus) ->getByIsQuiz($filterIsQuiz) ->getByIsHomepage($filterIsHomepage) ->with('voteCategory') ->with('creator') ->getByVoteCategoryId($filterVoteCategoryId) ->count();
期望格式化效果:
$totalVotesCount = Vote::getByName($filterName, true) ->getByStatus($filterStatus) ->getByIsQuiz($filterIsQuiz) ->getByIsHomepage($filterIsHomepage) ->with('voteCategory') ->with('creator') ->getByVoteCategoryId($filterVoteCategoryId) ->count();
配置步骤如下:
- 打开设置面板:使用快捷键
Ctrl+Alt+S(Windows/Linux)或Cmd+,(Mac),或通过顶部菜单「File」→「Settings」(Windows/Linux)/「PhpStorm」→「Preferences」(Mac)进入。 - 定位到PHP代码风格配置:左侧导航依次展开「Editor」→「Code Style」→「PHP」。
- 调整链式调用缩进规则:
- 切换到「Wrapping and Braces」标签页。
- 找到「Chained method calls」分组,取消勾选「Align when multiline」选项(该选项会让链式调用对齐到赋值语句的等号位置)。
- 确保「Indent chained calls」的缩进值设置为你需要的空格数(比如4,对应示例中的效果)。
- 保存配置:点击「Apply」→「OK」,之后执行格式化代码操作(
Ctrl+Alt+L/Cmd+Opt+L)即可生效。
内容的提问来源于stack exchange,提问作者mstdmstd
相关产品推荐
相关产品推荐

