Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chop down function arguments, but keep as-is if one argument is a multi line array and line is not to long

I have been playing with all the PhpStorm formatting options, but can't find a way to have if behave the way I want.

So basically I want PhpStorm to:

1. turn this:

myfunction('hello',
    'world');

Into this:

myfunction(
    'hello',
    'world'
);

2. keep this as is:

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

Also this shouldn't be reformatted:

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

Is this possible?

like image 909
Korri Avatar asked Apr 13 '17 18:04

Korri


1 Answers

As I know at this moment it is impossible.

Now to get this ability

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

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

you can setup options in this position:

enter image description here

But to setup wrapping on different params in new line

myfunction(
    'hello',
    'world'
);

you need another option list:

enter image description here

But in this case wrapping of array doesn't consist with your conditions.

Leave your feature request on JetBrains issue tracker. Only they can help you with this feature.

You need some option like Don't wrap array declaration.

But also you have one collision in condition: if you want arguments on new line in this case

myfunction(
    'hello',
    'world'
);

why you don't want it this?

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

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

Or even maybe you need option like Leave array declaration braces with comma/brace in method call. In that case it would work in way like

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

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

But here you also need some option like Don't wrap argument if it no long and contain array declaration.

IMHO the best way to resolve this issue is leave feature request with well describe rules of wrapping like what to do in next cases

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

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

Also what to do with PHP 5.3- array declaration array('key' => 'value') in method calls.

like image 76
Pavlo Zhukov Avatar answered Oct 05 '22 06:10

Pavlo Zhukov