coding-standard icon indicating copy to clipboard operation
coding-standard copied to clipboard

Allow parentheses around arrow function body

Open MidnightDesign opened this issue 4 years ago • 2 comments

I would like to be able to use the UselessParentheses sniff as it is right now, but disable it when used around an arrow function body like this:

$fn = fn(SomeVeryLongClassNameHere $foo): AnotherPrettyLongClassName => (
    $foo->doSomethingImpressive(trim('This is just here to demonstrate a long function body'))
);

That's basically a pattern from the JavaScript/React world that I would love to use in PHP while still detecting really useless parentheses.

Of course, one could argue that you can just use the following style:

$fn = fn(SomeVeryLongClassNameHere $foo): AnotherPrettyLongClassName =>
    $foo->doSomethingImpressive(trim('This is just here to demonstrate a long function body'));

But that's not as nice in my optinion.

MidnightDesign avatar Jul 02 '20 08:07 MidnightDesign

I think the problem is alittle bit wider - it blaims also on this:

(new SomeClass())
    ->someMethod();

programmador avatar Aug 27 '21 16:08 programmador

Sorry, It actually seems like my mention about "new" is not relevant. I thought that SlevomatCodingStandard.PHP.UselessParentheses was blaiming but it was SlevomatCodingStandard.ControlStructures.NewWithoutParentheses which could be disabled separately

programmador avatar Aug 27 '21 17:08 programmador