coding-standard
coding-standard copied to clipboard
Allow parentheses around arrow function body
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.
I think the problem is alittle bit wider - it blaims also on this:
(new SomeClass())
->someMethod();
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