Stop PhpStorm from adding a new line after function declaration when arguments split across multiple lines

青春壹個敷衍的年華 提交于 2019-12-07 07:36:27

问题


In my PhpStorm 8.0.3 code style, I have set it to add a new line after a function declaration, which works fine.

Problem is now I'm in a new project that follows the PSR-2 Standards, which say that the opening brace of a function MUST be placed in the same line that the closing parenthesis of the function arguments when these split across multiple lines, as you can see here.

I want this when arguments split across multiple lines...

public function myMethod(
    MyClass $arg1,
    $arg2 = null
) {
    // method body
}

...and this when they are all in the same line...

public function myMethod(MyClass $arg1, $arg2 = null)
{
    // method body
}

I was trying to search for that option but I couldn't find it - I know I can decide whether I want to add the new line for all functions, but I need it only in these particular occasions.


回答1:


In the File -> Settings dialogue, under Editor -> Code Style -> PHP select Wrapping and Braces tab on the right hand side.

Find the Function declaration parameters block and check the main control, here you have a bunch of options regarding wrapping parameters and few other options in this block to control braces placement. Also look at the Braces placement block above.




回答2:


As a complement to @marekful's answer. To make it clearer, these are the 2 settings needed to achieve what I wanted:



来源:https://stackoverflow.com/questions/29805484/stop-phpstorm-from-adding-a-new-line-after-function-declaration-when-arguments-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!