PhpStorm “Reformat Code” 在 PHP () 调用时使用换行符断行


PhpStorm "Reformat Code" breaks line at PHP () calls using newline

假设我有这样一行PHP代码:

if ($this->request->getModuleName() == 'abc' && $this->request->getControllerName() == 'test' && $this->request->getActionName() == 'test') {

然后我使用 PhpStorms "重新格式化代码"功能来重新格式化代码,它变成这样:

if ($this->request && $this->request->getModuleName(
    ) == 'abc' && $this->request->getControllerName(
    ) == 'test' && $this->request->getActionName() == 'test'
) {

但是为什么它在 a 之后( 和 a 之前)添加新行?它不应该更好地打破 &&?像这样,可读性更好:

if ($this->request && $this->request->getModuleName() == 'abc'
    && $this->request->getControllerName() == 'test' 
    && $this->request->getActionName() == 'test'
) {

我在 PhpStorms 设置中找不到解决此问题的选项。最大行长度设置为 120 个字符。

检查你的phpstorm代码样式设置。这应该会有所帮助

    /
  • phpstorm/help/configuring-code-style
  • /
  • phpstorm/help/reformatting-source-code
  • /
  • phpstorm/help/code-style