我一直在使用所有的PhpStorm格式设置选项,但是找不到一种可以按照我想要的方式运行的方法。

所以基本上我希望PhpStorm:

1.转动此:

myfunction('hello',
    'world');

变成这个:

myfunction(
    'hello',
    'world'
);

2.保持其与相同的方式:

myfunction([
    'hello' => 'world',
]);

另外,这不应该重新格式化:

myfunction($variableOne, [
    'hello' => 'world',
]);

这可能吗?

最佳答案

据我所知,这是不可能的。

现在获得这种能力

myfunction([
    'hello' => 'world',
]);

myfunction($variableOne, [
    'hello' => 'world',
]);

您可以在以下位置设置选项:

phpstorm - 砍掉函数参数,但如果一个参数是多行数组且行不长,则保持原样-LMLPHP

但是要在新行中设置不同参数的包装
myfunction(
    'hello',
    'world'
);

您需要另一个选项列表:

phpstorm - 砍掉函数参数,但如果一个参数是多行数组且行不长,则保持原样-LMLPHP

但是在这种情况下,数组的包装不符合您的条件。

将功能请求保留在JetBrains issue tracker上。只有他们可以帮助您使用此功能。

您需要一些类似Don't wrap array declaration的选项。

但同时您也有一个碰撞情况:
如果您想在这种情况下换行
myfunction(
    'hello',
    'world'
);

为什么你不想要这个?
myfunction(
    $variableOne, [
        'hello' => 'world',
    ]
);

myfunction(
    [
        'hello' => 'world',
    ]
);

甚至也许您需要像Leave array declaration braces with comma/brace in method call这样的选项。在这种情况下,它会像
myfunction($variableOne, [
    'hello' => 'world',
]);

myfunction([
    'hello' => 'world',
]);

但是在这里,您还需要一些选项,例如Don't wrap argument if it no long and contain array declaration

恕我直言,解决此问题的最佳方法是请假功能请求,并详细说明包装规则,如在接下来的情况下该怎么做
myfunction($variableOne, $variableTwo, [
    'hello' => 'world',
]);

myfunction($variableOne, $variableTwo, [
    'hello' => 'world',
], [
    'another' => 'array',
]);

还有在方法调用中使用PHP 5.3-数组声明array('key' => 'value')的方法。

关于phpstorm - 砍掉函数参数,但如果一个参数是多行数组且行不长,则保持原样,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43399629/

10-12 07:37
查看更多